Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Can the function getline() from stdio.h coexist with the one in K&R88?

I'm knee-deep in [K&R88] and I get chided by gcc because the function getline(), which K&R use as example and practise material, is now in stdio.h (and has been since around 2010, I'm told.)

Would there be any manner to tell the compiler to play it like it's 1988 and to have my homespun version supersede the one from the library ?

(yes it's futile, but wadding in [K&R88] is my new hobby ;-)

Obligatory compiler output :

gcc -g -Wall -o "pgm" "pgm.c" (in directory: /home/eric/Development/6.087)
pgm.c:9:7: error: conflicting types for ‘getline’
    9 | char *getline(){
      |       ^~~~~~~
In file included from pgm.c:1:
/usr/include/stdio.h:616:18: note: previous declaration of ‘getline’ was here
  616 | extern __ssize_t getline (char **__restrict __lineptr,
      |                  ^~~~~~~
Compilation failed.
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The getline function that conflicts with yours isn't part of standard C - it's POSIX's getline.

If you compile with standard C using -std:

gcc -g -Wall -std=c17 -o pgm pgm.c

you can avoid the conflict.

Having said that there's no reason to learn from K&R C (it's more of a reference imo) if you're starting out in C. And we're not going back to 1988 either ;-)

The language has changed a lot since and there's a good list of recommendations available at The Definitive C Book Guide and List.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!