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
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.'
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
> 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 ***
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.
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
>> 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
> 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.
weird, isnt' it?
Francisco
>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
> 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.
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"