Jon TURNEY
2015-02-17 18:24:54 UTC
Consider the following:
$ cat test.c
#include <string.h>
#include <stdlib.h>
int main()
{
long long i = random();
return ffsll(i);
}
ffsll() is a GNU extension and should be prototyped when _GNU_SOURCE is
defined.
random() is in SUSv2 and requires _XOPEN_SOURCE=500
$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’
This is correct
$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’
This looks like a problem with newlib's sys/cdefs.h. _XOPEN_SOURCE
causes _POSIX_C_SOURCE to be defined, which prevents _GNU_SOURCE from
being considered.
$ gcc test.c -Wall -ansi -D_GNU_SOURCE
test.c: In function ‘main’:
test.c:7:2: warning: implicit declaration of function ‘random’
_GNU_SOURCE is supposed to imply some value of _XOPEN_SOURCE, but only
actually turns on __XSI_VISIBLE.
The patch I wrote for cygwin's stdlib.h [1] explicitly checks
_XOPEN_SOURCE. Should this be a check for XSI_VISIBLE? or should
cdefs.h also define _XOPEN_SOURCE (and all the other feature test macros
that _GNU_SOURCE is defined to be equivalent to)?
[1] https://cygwin.com/ml/cygwin-patches/2013-q4/msg00004.html
$ cat test.c
#include <string.h>
#include <stdlib.h>
int main()
{
long long i = random();
return ffsll(i);
}
ffsll() is a GNU extension and should be prototyped when _GNU_SOURCE is
defined.
random() is in SUSv2 and requires _XOPEN_SOURCE=500
$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’
This is correct
$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’
This looks like a problem with newlib's sys/cdefs.h. _XOPEN_SOURCE
causes _POSIX_C_SOURCE to be defined, which prevents _GNU_SOURCE from
being considered.
$ gcc test.c -Wall -ansi -D_GNU_SOURCE
test.c: In function ‘main’:
test.c:7:2: warning: implicit declaration of function ‘random’
_GNU_SOURCE is supposed to imply some value of _XOPEN_SOURCE, but only
actually turns on __XSI_VISIBLE.
The patch I wrote for cygwin's stdlib.h [1] explicitly checks
_XOPEN_SOURCE. Should this be a check for XSI_VISIBLE? or should
cdefs.h also define _XOPEN_SOURCE (and all the other feature test macros
that _GNU_SOURCE is defined to be equivalent to)?
[1] https://cygwin.com/ml/cygwin-patches/2013-q4/msg00004.html