A small issue with _GNU_SOURCE
Corinna Vinschen
vinschen@redhat.com
Sat Feb 21 21:45:00 GMT 2015
On Feb 19 14:02, Jon TURNEY wrote:
> Consider the following:
>
> $ cat test.c
>
> #include <string.h>
>
> int main()
> {
> strdup("test");
> return ffsll(0);
> }
>
> ffsll() is a GNU extension and should be prototyped when _GNU_SOURCE is
> defined.
>
> strdup() is in SUSv2 and requires _XOPEN_SOURCE=500
>
> $ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=500
> test.c: In function ‘main’:
> test.c:8:2: warning: implicit declaration of function ‘ffsll’
>
> I think this is correct
>
> $ gcc test.c -Wall -ansi -D_GNU_SOURCE
>
> Since _GNU_SOURCE implies _XOPEN_SOURCE=700, this is as expected.
>
> $ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=500 -D_GNU_SOURCE
> test.c: In function ‘main’:
> test.c:8:2: warning: implicit declaration of function ‘ffsll’
>
> This looks like a problem with the way _GNU_SOURCE has been added to
> newlib's sys/cdefs.h. _XOPEN_SOURCE causes _POSIX_C_SOURCE to be defined,
> which prevents _GNU_SOURCE from being considered.
>
> I'm not sure about the right way to fix this.
Maybe by changing the evaluation order in sys/cdefs.h.
_GNU_SOURCE implies "everything and the kitchen sink" as the comment
says,
#define __POSIX_VISIBLE 200809
#define __XSI_VISIBLE 700
#define __BSD_VISIBLE 1
#define __ISO_C_VISIBLE 2011
#define __GNU_VISIBLE 1
so it might be prudent to check for _GNU_SOURCE before checking for
_XOPEN_SOURCE, instead of checking only if _POSIX_SOURCE/_POSIX_C_SOURCE
is not set.
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20150221/be12e28c/attachment.sig>
More information about the Newlib
mailing list