Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda