Jorgen Grahn said:
...
You cannot expect that having _GNU_SOURCE defined and then undefing it
is the same thing as it never being enabled in the first place.
Except that at least some of the documentation leads me to expect
exactly that!
The man page for getline says:
#define _GNU_SOURCE
#include <stdio.h>
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
and the man page for the feature test macros says:
In a few cases, manual pages use a shorthand for expressing the
feature test macro requirements (this example from readahead(2)):
#define _GNU_SOURCE
#include <fcntl.h>
ssize_t readahead(int fd, off64_t *offset, size_t count);
This format is employed in cases where only a single feature test
macro can be used to expose the function declaration, and that
macro is not defined by default.
The reality seems to be that _GNU_SOURCE is defined by default and not
getting this declaration is therefore not as simple as never
defining _GNU_SOURCE. By trying all 11 feature macros I've found
that it seems to be included unless __STRING_ANSI__ is defined. Then,
and only then, is it controlled by GNU_SOURCE. Curiously, the same
method does not work for other declarations whose documentation looks
similar.
Internally in stdio.h it's enabled by _USE_GNU, which in turn is
enabled back in features.h -- which by the way documents which defines
you may safely use to enable non-standard stuff.
I don't think the documentation is up-to-date. In fact, that is
probably the only issue here. The docs suggest that this feature needs
to be turned on whereas it needs to be turned off.
Your "by the way" suggests that I just needed to RTFM and I've have been
enlightened, but I am an avid reader of manuals and it was the manual
that led me astray.
So the bottom line for me is: if you tell the compiler "I want all
kinds of odd GNU extensions", you'd better be prepared to get all
kinds of odd GNU extensions ...
I always compile in strict mode, and when I need something
non-standard I enable it (using one of the BSD or POSIX defines; I
never or almost never enable GNU stuff because I cannot remember what
that stuff is).
That is, in fact, what I do. I was simply trying to explain what other
people seem to have seen so as to shed some light on when and how you
get this declaration.