Bug 65128 - remove "linux" and "unix" from preprocessor macros from cpp-5
Summary: remove "linux" and "unix" from preprocessor macros from cpp-5
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2015-02-20 01:15 UTC by Shawn Landden
Modified: 2015-12-28 05:10 UTC (History)
0 users

See Also:
Target: *-*-linux, *-*-unix, *-*-sun
Known to work:
Known to fail:
Last reconfirmed:

remove legacy includes (1.21 KB, patch)
2015-02-27 18:45 UTC, Shawn Landden
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Shawn Landden 2015-02-20 01:15:32 UTC
I just spent like a whole hour until I realized that cpp defines "linux" which gives this confusing error:

src/systemctl/bootspec.h:40:15: error: expected identifier or ‘(’ before numeric constant
         char *linux;
We should remove these defines from gcc 5, and force programs to check __unix__ and __linux__
Comment 1 Andrew Pinski 2015-02-20 01:38:15 UTC
bcc76966 (ghazi         2003-11-29 03:08:13 +0000  45)  builtin_define_std ("linux");                           \
bcc76966 (ghazi         2003-11-29 03:08:13 +0000  46)  builtin_define_std ("unix");                            \
Comment 2 Richard Biener 2015-02-20 07:44:04 UTC
They are indeed legacy defines.  More affected systems:

dragonfly.h:       builtin_define_std ("unix");         \
freebsd-spec.h: builtin_define_std ("unix");                                   \
gnu.h:  builtin_define_std ("unix");            \
kfreebsd-gnu.h: builtin_define_std ("unix");            \
knetbsd-gnu.h:  builtin_define_std ("unix");            \
kopensolaris-gnu.h:     builtin_define_std ("unix");            \
linux.h:        builtin_define_std ("linux");                           \
linux.h:        builtin_define_std ("unix");                            \
sol2.h: builtin_define_std ("unix");                    \
sol2.h: builtin_define_std ("sun");                     \
Comment 3 Shawn Landden 2015-02-27 18:45:14 UTC
Created attachment 34892 [details]
remove legacy includes
Comment 4 Andrew Pinski 2015-12-28 05:10:00 UTC

The C standard requires that all system-specific macros be part of the reserved namespace. All names which begin with two underscores, or an underscore and a capital letter, are reserved for the compiler and library to use as they wish. However, historically system-specific macros have had names with no special prefix; for instance, it is common to find unix defined on Unix systems. For all such macros, GCC provides a parallel macro with two underscores added at the beginning and the end. If unix is defined, __unix__ will be defined too. There will never be more than two underscores; the parallel of _mips is __mips__.

We are slowly phasing out all predefined macros which are outside the reserved namespace. You should never use them in new programs, and we encourage you to correct older code to use the parallel macros whenever you find it. We don't recommend you use the system-specific macros that are in the reserved namespace, either. It is better in the long run to check specifically for features you need, using a tool such as autoconf.