|
Home > Archive > Unix Programming > March 2005 > User Defined Macros for UNIX Standards
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
User Defined Macros for UNIX Standards
|
|
| Michael B Allen 2005-03-16, 2:53 am |
| On Tue, 15 Mar 2005 08:31:55 -0500, Geoff Clare wrote:
> Others have answered your question about Makefile variables, but you
> should also be aware that _XOPEN_VERSION is not something you should try
> and set this way. It is defined by the implementation (in unistd.h).
> The same applies to _POSIX_VERSION if you were planning to set that for,
> say, "./copt posix90".
>
> For the various versions of POSIX/SUS you should only define
> _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE and/or
> _XOPEN_SOURCE_EXTENDED.
Ok, so from looking at http://predef.sourceforge.net/prestd.html and
glibc's features.h I gather you set the following for the various
standards?
Standard User Defined Macros copt identifier
POSIX.1 _POSIX_C_SOURCE=1 posix1
POSIX.2 _POSIX_C_SOURCE=2 posix2
POSIX.1b _POSIX_C_SOURCE=199309L posix1b
POSIX.1c _POSIX_C_SOURCE=199506L posix1c
XPGv3 _XOPEN_SOURCE xpgv3
XPGv4 _XOPEN_SOURCE xpgv4
SUS UNIX95 _XOPEN_SOURCE_EXTENDED unix95
SUSv2 UNIX98 _XOPEN_SOURCE=500 unix98
SUSv3 UNIX01 _XOPEN_SOURCE=600 unix01
GNUC _GNU_SOURCE gnu
BSD4.3 _BSD_SOURCE bsd
SVID _SVID_SOURCE svid
Is there any way to specify XPGv3 vs XPGv4?
Should I leave some of these out b/c their very old or broken?
Are these all mutually exclusive?
Are the last 2 gcc specific?
Thanks,
Mike
| |
| Bjorn Reese 2005-03-16, 6:02 pm |
| Michael B Allen wrote:
> Ok, so from looking at http://predef.sourceforge.net/prestd.html and
[...]
> Is there any way to specify XPGv3 vs XPGv4?
Yes. Look at the above URL once more ;)
> Should I leave some of these out b/c their very old or broken?
You should only keep the ones you use. So you need to determine
(1) which platforms you want to support, and (2) what functionality
you want to detect and use (or provide your own implementation of).
> Are these all mutually exclusive?
Not in general. For example, UNIX98 also includes UNIX95.
--
mail1dotstofanetdotdk
| |
| Geoff Clare 2005-03-17, 5:55 pm |
| Michael B Allen <mba2000@ioplex.com> wrote, on Wed, 16 Mar 2005:
>
> Ok, so from looking at http://predef.sourceforge.net/prestd.html and
That page seems to be confused about which macros are predefined (by
the system) and which need to be defined by the user/application.
Anything it lists that doesn't have "SOURCE" in the name is something
defined by the system that you can use to find out what is supported.
The "SOURCE" ones are things you define to request the features (or
standards) you want to be enabled.
> glibc's features.h I gather you set the following for the various
> standards?
>
> Standard User Defined Macros copt identifier
> POSIX.1 _POSIX_C_SOURCE=1 posix1
"POSIX.1" is ambiguous. Most people would take it as referring
to POSIX.1-2001 now. When you want to refer to old versions of
POSIX.1 you should specify the date. (On the prestd.html page
this is listed as ISO/IEC 9945-1:1990, i.e. POSIX.1-1990).
I would suggest the copt identifiers posix90 for POSIX.1-1990
and posix01 for POSIX.1-2001.
The actual POSIX.1-1990 standard had no mention of _POSIX_C_SOURCE
(the value of 1 for that macro is retrospective). So to request
POSIX.1-1990 you should just define _POSIX_SOURCE.
For POSIX.1-2001 you should define _POSIX_C_SOURCE=200112L
> POSIX.2 _POSIX_C_SOURCE=2 posix2
> POSIX.1b _POSIX_C_SOURCE=199309L posix1b
> POSIX.1c _POSIX_C_SOURCE=199506L posix1c
> XPGv3 _XOPEN_SOURCE xpgv3
> XPGv4 _XOPEN_SOURCE xpgv4
The XPG's are normally referred to as just XPG3 and XPG4 (without
a "v").
> SUS UNIX95 _XOPEN_SOURCE_EXTENDED unix95
Officially you are supposed to define both _XOPEN_SOURCE and
_XOPEN_SOURCE_EXTENDED for UNIX95. However, some systems do
accept just _XOPEN_SOURCE_EXTENDED on its own.
> SUSv2 UNIX98 _XOPEN_SOURCE=500 unix98
> SUSv3 UNIX01 _XOPEN_SOURCE=600 unix01
It might be better to call this unix03, since that's what the
Open Group's UNIX trademark registrations for SUSv3 are called.
> GNUC _GNU_SOURCE gnu
> BSD4.3 _BSD_SOURCE bsd
> SVID _SVID_SOURCE svid
I think these three are only meaningful to glibc.
On SVR4 there was no way to request SVID. You just had to ensure
you didn't define any of the more restrictive macros (i.e. don't
use the compiler option to restrict to just C89, and don't define
_POSIX_SOURCE or _XOPEN_SOURCE) and then you would get the whole
namespace.
> Is there any way to specify XPGv3 vs XPGv4?
No there isn't. If you define _XOPEN_SOURCE on an XPG4 system you
will get XPG4. If you define it on an XPG3 system you will get
XPG3. There was no provision back then for them to co-exist.
> Should I leave some of these out b/c their very old or broken?
I don't think it is worth including XPG3. POSIX.2 is also
dubious as it had very little C library stuff in it, and it
all went into XPG4.
> Are these all mutually exclusive?
No. There are complicated interrelationships. In particular,
POSIX.1-2001 and SUSv3 are one and the same document. So strictly
speaking you should have something like:
POSIX.1-2001/SUSv3 with XSI option _XOPEN_SOURCE=600 unix03
POSIX.1-2001/SUSv3 without XSI _POSIX_C_SOURCE=200112L posix01
> Are the last 2 gcc specific?
I think they're glibc-specific, not gcc.
--
Geoff Clare <netnews@gclare.org.uk>
| |
| Bjorn Reese 2005-03-17, 5:55 pm |
| Geoff Clare wrote:
> That page seems to be confused about which macros are predefined (by
> the system) and which need to be defined by the user/application.
> Anything it lists that doesn't have "SOURCE" in the name is something
> defined by the system that you can use to find out what is supported.
> The "SOURCE" ones are things you define to request the features (or
> standards) you want to be enabled.
Sorry about the confusion. I have cleaned it up now.
Unfortunately, I still don't know how to distinguish between XPG4 and
UNIX95 without using _XOPEN_SOURCE_EXTENDED.
--
mail1dotstofanetdotdk
| |
| Geoff Clare 2005-03-18, 7:51 am |
| Bjorn Reese <breese@see.signature> wrote, on Thu, 17 Mar 2005:
>
> Sorry about the confusion. I have cleaned it up now.
>
> Unfortunately, I still don't know how to distinguish between XPG4 and
> UNIX95 without using _XOPEN_SOURCE_EXTENDED.
You can distinguish them by checking whether _XOPEN_UNIX is defined.
(It is defined for UNIX95 but not for XPG4.)
Note also that the _POSIX_* and _XOPEN_* version macros are defined
in <unistd.h>, they are not predefined by the compiler.
--
Geoff Clare <netnews@gclare.org.uk>
|
|
|
|
|