This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Defining _GNU_SOURCE hides the declaration of aligned_alloc

On 2/2/2016 5:27 PM, Ken Brown wrote:
The issue in the Subject line came up in connection with an emacs bug

Here's a test case:

$ cat test.c
#define _GNU_SOURCE
#include <stdlib.h>

main ()
   aligned_alloc (1, 1);

$ gcc test.c -Wimplicit-function-declaration
test.c: In function âmainâ:
test.c:7:3: warning: implicit declaration of function âaligned_allocâ

The cause is that the declaration of aligned_alloc in stdlib.h is
guarded by #if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L; but
defining _GNU_SOURCE causes __ISO_C_VISIBLE to be defined as 1999.
Here's an excerpt from /usr/include/sys/cdefs.h showing how this happens:

/* Deal with _GNU_SOURCE, which implies everything and the kitchen sink */
#ifdef _GNU_SOURCE
#define    _XOPEN_SOURCE        700
#if _XOPEN_SOURCE - 0 >= 700
#define    _POSIX_C_SOURCE        200809
#if _POSIX_C_SOURCE >= 200809
#define    __ISO_C_VISIBLE        1999
#endif /* _POSIX_C_SOURCE */

According to the discussion of the emacs bug I mentioned, Linux and
FreeBSD don't have this issue.  Should Cygwin's headers be changed to
conform to those other platforms?

Paul Eggert says they should:

Defining _GNU_SOURCE should make aligned_alloc visible regardless of whether -std=c99 is specified. This is because defining _GNU_SOURCE means, "Make GNU symbols visible even when compiling pedantically." This is OK, since the C standard says the behavior is undefined whenever the user defines a reserved symbol like _GNU_SOURCE.


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]