This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/2082: g++ defines _GNU_SOURCE by default
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/2082: g++ defines _GNU_SOURCE by default
- From: dbaron at fas dot harvard dot edu
- Date: 24 Feb 2001 15:25:05 -0000
- Reply-To: dbaron at fas dot harvard dot edu
>Number: 2082
>Category: c++
>Synopsis: g++ defines _GNU_SOURCE by default
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Feb 24 07:26:04 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: L. David Baron
>Release: unknown-1.0
>Organization:
>Environment:
gcc version 3.0 20010222 (prerelease)
RedHat Linux 7.0
>Description:
On the gcc-3_0-branch (from 2001-02-22), _GNU_SOURCE is defined by g++ by default. It is not defined by gcc by default. In older versions of gcc and g++, it was not defined by default using either compiler.
This makes it somewhat more difficult to write autoconf tests, since certain system structures differ based on whether _GNU_SOURCE (and, from features.h, __USE_GNU) are defined. For example (the one that causes Mozilla not to build), sys/utsname.h includes the text:
# ifdef __USE_GNU
char domainname[_UTSNAME_DOMAIN_LENGTH];
# else
char __domainname[_UTSNAME_DOMAIN_LENGTH];
# endif
Since _GNU_SOURCE is defined when compiling in C++ but not when compiling in C, the result of an autoconf test for whether to use domainname or __domainname that is in C is not valid in C++, and the result of an autoconf test in C++ is not valid in C.
If there are good reasons for wanting _GNU_SOURCE to be defined by default in C++ and not C, then those might override this. However, this is a significant disadvantage of doing it the current way.
>How-To-Repeat:
Compile the following file using g++ and with gcc (or with gcc as a .cpp file and as a .c file):
-----
#include <stdio.h>
#ifdef __cplusplus
const char *kLanguage = "C++";
#else
const char *kLanguage = "C";
#endif
#ifdef _GNU_SOURCE
const char *kDefined = "is";
#else
const char *kDefined = "is not";
#endif
int main(void)
{
printf("_GNU_SOURCE %s defined in %s.\n", kDefined, kLanguage);
return 0;
}
-----
In the gcc-3_0-branch, _GNU_SOURCE is defined when using g++ or when the file extension is .cpp. In my older gcc (which happens to be RedHat's gcc-2.96, but never mind that, since based on the Mozilla autoconf test, _GNU_SOURCE was never defined differently in C and C++ on a system that had a sys/utsname.h like mine), _GNU_SOURCE was not defined in either C or C++.
What's causing this may (although I haven't checked) be the #define _GNU_SOURCE in include/g++-v3/i686-pc-linux-gnu/bits/os_defines.h
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: