is _GNU_SOURCE defined by gcc ?

Florian Weimer Florian.Weimer@RUS.Uni-Stuttgart.DE
Fri Nov 24 06:54:00 GMT 2000


Levente Farkas <lfarkas@mindmaker.hu> writes:

> the followning simple code can prodcuce non-gnu both on red hat 6.2 and
> 7.0 (with the default gcc) at the same time with the latest cvs gcc 
> it's print gnu. what is the difference and how can I force gcc to 
> define _GNU_SOURCE (-D_GNU_SOURCE seems to be a solution but I don't
> know whether is there any reason that it's not defined by default or not)?

When you use the GNU C Library, you have to define _GNU_SOURCE if you
want to use certain extensions.  These extensions are not available on
some non-GNU systems; the idea is that this prevents you from
accidently using them and making your software less portable.

It's even documented in the GNU C Library manual ("Feature Test
Macros"):

|  - Macro: _GNU_SOURCE
|      If you define this macro, everything is included: ISO C89,
|      ISO C99, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU
|      extensions.  In the cases where POSIX.1 conflicts with BSD, the
|      POSIX definitions take precedence.

BTW: This hasn't much to do with GCC (the compiler itself), so
gcc@gcc.gnu.org is not appropriate for this kind of discussion.

-- 
Florian Weimer 	                  Florian.Weimer@RUS.Uni-Stuttgart.DE
University of Stuttgart           http://cert.uni-stuttgart.de/
RUS-CERT                          +49-711-685-5973/fax +49-711-685-5898


More information about the Gcc mailing list