Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda