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