sigset_t and gcc

J

Jade Fox

Can anybody tell me what is wrong with the following code?
It compiles ok with 'gcc file.c',
but not 'gcc -ansi file.c' or 'gcc -std=c99 file.c'.
It complains that 'sigset_t' is undeclared.
What options am I missing? Thanks

#include <signal.h>

int main()
{
sigset_t set;
}
 
C

Chris Dollin

Jade said:
Can anybody tell me what is wrong with the following code?
It compiles ok with 'gcc file.c',
but not 'gcc -ansi file.c' or 'gcc -std=c99 file.c'.
It complains that 'sigset_t' is undeclared.
What options am I missing? Thanks

#include <signal.h>

int main()
{
sigset_t set;
}

I'd hypothesise that sigset_t is not in the ISO standards for C.

<fx:peek/>

Can't see it in C90.

Perhaps it's POSIX.
 
R

Richard Bos

Can anybody tell me what is wrong with the following code?
It compiles ok with 'gcc file.c',
but not 'gcc -ansi file.c' or 'gcc -std=c99 file.c'.

So it compiles in use-every-GNU-extension-you-can-find mode, but not in
ISO mode. Gosh, what _would_ be the problem?
It complains that 'sigset_t' is undeclared.
What options am I missing? Thanks

None. You're missing the fact that there is no such thing as sigset_t in
the Standard.

Richard
 
I

Irrwahn Grausewitz

[OT]
By specifying -ansi or -std=c89 or std=c99 you told gcc that you
only want to use those language features that are defined in the
corresponding standards. sigset_t isn't among those features.
[/OT]
I'd hypothesise that sigset_t is not in the ISO standards for C.

<fx:peek/>

Can't see it in C90.

And it's not mentioned in C99 either.

Regards
 
F

Floyd Davidson

Can anybody tell me what is wrong with the following code?
It compiles ok with 'gcc file.c',
but not 'gcc -ansi file.c' or 'gcc -std=c99 file.c'.
It complains that 'sigset_t' is undeclared.
What options am I missing? Thanks

#include <signal.h>

int main()
{
sigset_t set;
}

The compiler is telling you sigset_t is not defined by the C
Standard, which also makes it off topic in this particular
newsgroup. The appropriate place to ask would be a group
specific to programming on your particular platform.

However...

It is a POSIX defined type (as opposed to a C99 type), and if
you put "#define _POSIX_SOURCE" at the top of your source file
it will likely have the desired effect.

A wild guess... but you might try looking in
/usr/include/signal.h where you'll probably note that it
includes <features.h>, which is a file you'll want to explore.
As soon as you are confused enough to *really* need help, go
find that platform specific group. :)
 
D

Dan Pop

In said:
Can anybody tell me what is wrong with the following code?
It compiles ok with 'gcc file.c',
but not 'gcc -ansi file.c' or 'gcc -std=c99 file.c'.
It complains that 'sigset_t' is undeclared.
What options am I missing? Thanks

#include <signal.h>

int main()
{
sigset_t set;
}

Here's the full story. When the implementation is used in conforming
mode (which is partly achieved by gcc's options -ansi or -std=c99), the
standard headers are not allowed to declare/define *any* identifier in
the program name space that is not specified by the corresponding section
in the relevant standard (C89 for -ansi, C99 for -std=c99). Or neither
of these standards specifies sigset_t in the section dedicated to
<signal.h>, therefore this header is NOT allowed to declare/define this
identifier when included in *conforming* mode.

There are no such restrictions when the header is included in
non-conforming mode (there are no restrictions at all in this case),
so you'll get the definition of sigset_t if you use neither -ansi
nor any -std= option.

You have to opt between using non-standard features and invoking the
compiler in standard conforming mode, because you can't have both at the
same time. Be warned, however, that gcc is not a C compiler in its
default mode, it is a GNU C compiler. Certain invalid C programming
constructs are valid in GNU C. To get warnings for at least a subset
of them, use the -pedantic option (which is required as a companion
to -ansi or -std= to invoke the compiler in standard conforming
mode, too). -pedantic doesn't remove any declarations/definitions from
the included headers.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top