#define _POSIX_C_SOURCE and other defines

#define _POSIX_C_SOURCE and other defines

Post by T. Vogle » Wed, 12 Apr 2000 04:00:00



moin group,

I like to ask you all a kind of novice question I could not find an answer
for:

I am porting a library to a lot of operating systems (hp-ux, Solaris, aix,
linux to name a few). there are lots of confusing defines around like

_HPUX_SOURCE
_POSIX_C_SOURCE
_ALL_SOURCE
_XOPEN_SOURCE
POSIX_PTHREAD_SEMANTICS

where I found no short and concise definition what they

a) really mean (or are they really mean ;-)
b) if they should be defined during compilation
c) what value they should be defined to (if at all)

I tried to find something in the manufacturers documentations or in a paper
or FAQ in the WWW but failed.

can one of you please point me in the right direction ?

thank you !

Thomas

 
 
 

#define _POSIX_C_SOURCE and other defines

Post by Geoff Clar » Sat, 15 Apr 2000 04:00:00



>I am porting a library to a lot of operating systems (hp-ux, Solaris, aix,
>linux to name a few). there are lots of confusing defines around like
>_HPUX_SOURCE
>_POSIX_C_SOURCE
>_ALL_SOURCE
>_XOPEN_SOURCE
>POSIX_PTHREAD_SEMANTICS
>where I found no short and concise definition what they
>a) really mean (or are they really mean ;-)
>b) if they should be defined during compilation
>c) what value they should be defined to (if at all)

The *_SOURCE defines are called "Feature Test Macros".  They control
what symbols are visible in the system's headers during compilation.
With a standards-compliant C compiler, if you don't define any of
these macros then all that will be visible are the symbols allowed
by the C standard.  To use POSIX.1 symbols, for example, you must define
_POSIX_SOURCE before including any system headers.  (A common way to
do this is to put -D_POSIX_SOURCE in the compiler flags in makefiles.)

If your Linux system has a recent version of glibc (recent = 2.1.x),
then do an "info libc" and find the node called "Feature Test Macros"
for an explanation of most of these macros.  (Except that the last
paragraph of the part about _POSIX_C_SOURCE is incorrect - I have
reported it as a bug.)  The ones it won't explain are _ALL_SOURCE and
_HPUX_SOURCE.  These are used to make all the header symbols visible
on AIX and HP-UX respectively.  (They are equivalent to _GNU_SOURCE
for glibc.)

I haven't come across POSIX_PTHREAD_SEMANTICS before.  It must be
something specific to one of the systems you are using.
--



 
 
 

#define _POSIX_C_SOURCE and other defines

Post by Andrew Giert » Sat, 15 Apr 2000 04:00:00


 Geoff> I haven't come across POSIX_PTHREAD_SEMANTICS before.  It must
 Geoff> be something specific to one of the systems you are using.

It's a Solarisism. Defining it enables the standard-conforming version
of sigwait() rather than a bogus Solaris-threads version.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

1. gcc #define #define #define

Simple. There are several standards designed to alleviate
porting pains. ANSI C, POSIX, X/Open are the major ones.
As long as your program adheres to the above standards it
is easily portable. E.g. for most Xlib and/or Motif programs
it is only required that you need a different makefile
because of various include and lib directories. In fact,
Linux is one of platforms that provide both BSD and SysV
library calls and other features. Try to write or port
something to/from SunOS to IRIX then you will see what all
those #ifdefs are all about. :)

Let me find an example to back up my point: I write a
program and I need to find a way to zero out a memory
area. I found several library functions that can do that,
bzero() and memset(). I look at the bottom of the man
pages:

bzero() CONFORMING TO BSD 4.3

memset() CONFORMING TO SVID 3, BSD 4.3, ISO 9899

Now it is obvious that it is better to use the latter.

Unless, of course, I misunderstood you. What exactly are
you dealing with where you have problems with lots of #ifdefs?
Then maybe me or someone else can provide you some more
specific assistance?

--
<vladimip at uniserve com> | Good pings come in small packets
     Vancouver, BC | SIGSIG: signature too long (core dumped)
Things are more like they are today than they ever were before -
(From a crosspost between alt.suicide and alt.destroy.microsoft)

2. System 7-like x?

3. m4: how to define var if another defined

4. How to find out printer is in trouble in HP-UX

5. #if defined .... some problems....

6. bash2 & bash.....????

7. Help C language #define

8. Using an existing script and menu

9. How to define teh backspace key to work properly

10. Aliases in X - where defined?

11. fdisk: cannot well-define partition tables due to overlapping

12. looking for library defining _yylineno!

13. What defines the picture of an iconified application?