Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stdio.h function getline can't be compiled in

2,502 views
Skip to first unread message

Francisco Ares

unread,
Feb 20, 2004, 3:58:15 PM2/20/04
to
Hi all.

I've got this error message from gcc for a program "wasis.c"

wasis.c:129: warning: implicit declaration of function `getline'

this is the command line for gcc

gcc -g -Wall -pedantic -c -o wasis.o wasis.c

the include lines for the source code are:


#define __USE_GNU

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h> /* declare the 'stat' structure */
#include <sys/types.h>


What am I missing?

TIA
Francisco

James Kuyper

unread,
Feb 20, 2004, 4:43:22 PM2/20/04
to
Francisco Ares wrote:
>
> Hi all.
>
> I've got this error message from gcc for a program "wasis.c"
>
> wasis.c:129: warning: implicit declaration of function `getline'

Actually, that's a warning message, not an error message.



> this is the command line for gcc
>
> gcc -g -Wall -pedantic -c -o wasis.o wasis.c

This isn't a standard-conforming mode for gcc, so it's an off-topic
question for comp.std.c. You should post it to some other forum.

> the include lines for the source code are:
>
> #define __USE_GNU

With very few exceptions, use of an identifier starting with two
underscores makes the behavior of your program undefined, as far as the
C standard is concerned. "__USE_GNU" is not one of the few exceptions.

> #include <ctype.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <time.h>
> #include <unistd.h>
> #include <sys/stat.h> /* declare the 'stat' structure */
> #include <sys/types.h>
>
>
> What am I missing?

Well, for one thing, the rest of the source code for your program.
There's lots of things that could happen between the last line you
showed, and line 129, to justify that warning message. Since getline is
not a reserved identifier, it shouldn't be declared in any standar
headers, so long as you're using your compiler in standard-compliant
mode. Therefore, whether that warning message is justified (for a
compiler in conforming mode, with __USE_GNU removed) depends upon
whether or not your own code provides a declaration for 'getline.'

lawrenc...@ugsplm.com

unread,
Feb 20, 2004, 6:13:01 PM2/20/04
to
Francisco Ares <fra...@netscape.net> wrote:
>
> wasis.c:129: warning: implicit declaration of function `getline'
[...]
> What am I missing?

Something that declares getline, which is not a standard C function.
Nor is it a standard Posix or Single Unix Specification funtion, so it's
not too surprising that it's not declared in any standard header file.

And please note that comp.std.c is for discussing the C standard, not
for programming questions; those belong in comp.lang.c. But since your
question is about a non-standard function, it really doesn't belong
there, either.

-Larry Jones

In a minute, you and I are going to settle this out of doors. -- Calvin

Barry Margolin

unread,
Feb 20, 2004, 6:20:25 PM2/20/04
to
In article <d2fig1-...@jones.homeip.net>, lawrenc...@ugsplm.com
wrote:

> And please note that comp.std.c is for discussing the C standard, not
> for programming questions; those belong in comp.lang.c. But since your
> question is about a non-standard function, it really doesn't belong
> there, either.

But since he apparently didn't know that getline() is a non-standard
function, how could he be expected to know that it's off-topic for both
groups? Seems like a Catch-22 :)

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

James Kuyper

unread,
Feb 20, 2004, 6:32:09 PM2/20/04
to
Barry Margolin wrote:
>
> In article <d2fig1-...@jones.homeip.net>, lawrenc...@ugsplm.com
> wrote:
>
> > And please note that comp.std.c is for discussing the C standard, not
> > for programming questions; those belong in comp.lang.c. But since your
> > question is about a non-standard function, it really doesn't belong
> > there, either.
>
> But since he apparently didn't know that getline() is a non-standard
> function, how could he be expected to know that it's off-topic for both
> groups? Seems like a Catch-22 :)

If he's going to post questions to comp.std.c, he probably should get a
copy of the standard.

Somewhere the developer of that code should have documentation of some
kind for getline(), or he wouldn't even have had reason to use it.
Either that documentation, or the context in which the documentation is
available, might contain some hint of the fact that it's non-standard.
Unfortunately, that hint might take the form of the absence of an
indication that it's standard, which can be hard to notice.

Brian Inglis

unread,
Feb 20, 2004, 7:29:58 PM2/20/04
to
On 20 Feb 2004 12:58:15 -0800 in comp.std.c, fra...@netscape.net
(Francisco Ares) wrote:

You're either missing some code or the correct group.
grep your source files for a definition of getline().
Failing that: Standard C offers fgets(); C++ offers getline();
GNU offers readline(); and Google offers a macro definition:
#define getline(line,size,stream) \
((fgets( line, size, stream) != NULL) ? strlen(line) : -1)

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Brian....@CSi.com (Brian dot Inglis at SystematicSw dot ab dot ca)
fake address use address above to reply

those who know me have no need of my name

unread,
Feb 20, 2004, 10:27:41 PM2/20/04
to
in comp.std.c i read:

>> And please note that comp.std.c is for discussing the C standard, not
>> for programming questions; those belong in comp.lang.c. But since your
>> question is about a non-standard function, it really doesn't belong
>> there, either.
>
>But since he apparently didn't know that getline() is a non-standard
>function, how could he be expected to know that it's off-topic for both
>groups? Seems like a Catch-22 :)

we don't know that the op didn't know it was non-standard, after all there
was a __USE_GNU macro defined in the way it would need to be done to obtain
non-standard functionality from the headers.

it's also passé these days to read a group for a while before posting.

--
a signature

Kalle Olavi Niemitalo

unread,
Feb 21, 2004, 5:08:06 AM2/21/04
to
those who know me have no need of my name <not-a-rea...@usa.net> writes:

> we don't know that the op didn't know it was non-standard, after all there
> was a __USE_GNU macro defined in the way it would need to be done to obtain
> non-standard functionality from the headers.

GNU libc doesn't interpret __USE_GNU in that way though.
The actual feature test macros are listed in the manual.

Francisco Ares

unread,
Feb 21, 2004, 7:54:49 AM2/21/04
to
Sorry if I posted in the wrong place, but getline *is* defined withing
stdio.h from glibc v3.2.3

weird, isnt' it?

Francisco

those who know me have no need of my name

unread,
Feb 21, 2004, 8:54:04 AM2/21/04
to
in comp.std.c i read:

>Sorry if I posted in the wrong place, but getline *is* defined withing
>stdio.h from glibc v3.2.3
>
>weird, isnt' it?

yes. please send them a bug report.

--
a signature

Barry Margolin

unread,
Feb 21, 2004, 1:33:00 PM2/21/04
to
In article <5dc9cf2d.04022...@posting.google.com>,
fra...@netscape.net (Francisco Ares) wrote:

> Sorry if I posted in the wrong place, but getline *is* defined withing
> stdio.h from glibc v3.2.3

My guess is that it only declares it if you've enabled GNU extensions
(perhaps that's what the __USE_GNU macro does). If you include it in
standard-conforming mode, maybe it doesn't define extra functions.

Keith Thompson

unread,
Feb 21, 2004, 6:53:21 PM2/21/04
to
those who know me have no need of my name <not-a-rea...@usa.net> writes:

Don't bother. getline is defined in stdio.h only if the compiler is
invoked in non-conforming mode or if _GNU_SOURCE is defined.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"

0 new messages