[LC++]Best way to get sigaction header code included?

Torsten Rennett Torsten at Rennett.de
Tue Feb 18 18:04:01 UTC 2003


Hi Mark,

Dr Mark H Phillips wrote:
> Torsten showed me how the use of sigaction() rather than signal()
> could be used to solve a problem I was having.  This seems to work,
> but I'm having difficulty knowing the best way to ensure the sigaction
> code is included.
> 
> Doing
>   #include <signal.h>
> doesn't automatically call in the sigaction code.  On Solaris it seems
> I need to compile using a "-D__EXTENSIONS__" flag added.  On Linux
> I still haven't worked out how to do it.
> 
> >From what I've read on the web it appears the issue is that sigaction
> is a POSIX thing.  Presumably I need to tell the compiler/preprocessor
> that I want to compile as POSIX, but I'm not sure how to do this.  I
> tried "-D__USE_POSIX" under Linux but that didn't seem to work - it

read about "Feature Test Macros", e.g. in the libc-Info
(Node: Introduction -> Using the Library -> Feature Test Macros).
IIRC you have to set '-D_POSIX_SOURCE=1' or '-D_POSIX_C_SOURCE=199506L'.

'__USE_POSIX' and '__EXTENSIONS__' are internally used macros, note the
double underscore!  (You've got it from a lookup in the header files,
right?)  Do not use that, it's far from portable. 


> would appear I need to specify which particular version of POSIX I
> want to set???  All this seems a bit more complicated than I would
> have expected, so I'm wondering if there is a simpler way (and a
> portable way!).

Sorry, I don't know of a simpler way. Writing veritable portable
programs is not that way easy ... but possible :-)

> Oh, and will compiling it as POSIX compliant cause other problems
> down the track?

You have to make a decision (ideally before you started to code): 
Do you want to write a veritable portable program, or not?

If the answer is yes, then decide to which standard it should conform:
ISO C, POSIX.1, POSIX.2, SVID, X/Open, Single Unix Specification, ...
Then set the Feature Test Macros accordingly (in your Makefile or better
configure.in or something). Make sure that ALL your code (of the current
project/program) will be compiled with the SAME Feature Test Macros
settings! If not, you are asking for trouble ...

So, back to your point "compiling it as POSIX compliant cause other
problems down the track": 
Make your WHOLE program portable, not just a piece of it!

Torsten

--
Ingenieurbuero RENNETT      -- innovative Software-Entwicklung --
Torsten Rennett              
Ludwig-Thoma-Weg 14         E-Mail:     mailto:Torsten at Rennett.de
D-85551 Heimstetten         Telefon:              +49-89-90480538





More information about the tuxCPProgramming mailing list