About the Struct syntax.

I'm doing an application that uses Linux signals. Searching through the internet, I came across the following struct declaration

1
2
3
4
5
6
7
8
9
     struct  sigaction {
	     union {
		     void    (*__sa_handler)(int);
		     void    (*__sa_sigaction)(int, struct __siginfo *, void *);
	     } __sigaction_u;		     /* signal handler */
	     int     sa_flags;		     /* see signal options below */
	     sigset_t sa_mask;		     /* signal mask to apply */
     };


My question is: What does this mean? . Of course, i'm not talking about what the struct is for, but instead, about its syntax, and the meaning of all the elements here. What is this? :

 
void    (*__sa_handler)(int);


And.. what is this? :

1
2
3
	     union {
		     /*...*/;
	     } __sigaction_u;



Thanks in advance for the help!!
Last edited on
This void (*__sa_handler)(int); declares a variable called "__sa_handler" that is a pointer to a function that takes one int as an argument and returns void.

A union stores all of its members at the same location in memory.
Last edited on
Fantastic answer. Thanks a lot. I didn't even know about the datatype union .

By the way, do you know any tutorial about pointers to functions??
You need to investigate what is called the "right-left rule".

I googled a couple of explanations here:

http://www.codeproject.com/KB/cpp/complex_declarations.aspx#right_left_rule

http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html

It takes a little getting the hang of but with practice it gets easier.

This looks quite comprehensive...

http://www.newty.de/fpt/index.html
Thanks a lot!. Sorry if it took me some time to mark this as solved.
Topic archived. No new replies allowed.