* anything to do with pointer to functions maybe?
@ 2004-12-23 10:24 soraberri
2004-12-23 11:47 ` Jan-Benedict Glaw
2004-12-30 11:26 ` Glynn Clements
0 siblings, 2 replies; 4+ messages in thread
From: soraberri @ 2004-12-23 10:24 UTC (permalink / raw)
To: linux-c-programming
Hi all!
I'm having troubles understanding code:
what type is __sighandler_t if it is defined this way:?
typedef void (*__sighandler_t) (int);
and then, what does this definition mean:
#define SIG_IGN ((__sighandler_t) 1)
thanks very much if you know and you tell me ;·)
regards
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: anything to do with pointer to functions maybe?
2004-12-23 10:24 anything to do with pointer to functions maybe? soraberri
@ 2004-12-23 11:47 ` Jan-Benedict Glaw
2004-12-23 14:19 ` soraberri
2004-12-30 11:26 ` Glynn Clements
1 sibling, 1 reply; 4+ messages in thread
From: Jan-Benedict Glaw @ 2004-12-23 11:47 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1573 bytes --]
On Thu, 2004-12-23 11:24:39 +0100, soraberri <421246@posta.unizar.es>
wrote in message <cqe6ed$ldf$1@sea.gmane.org>:
> Hi all!
> I'm having troubles understanding code:
>
> what type is __sighandler_t if it is defined this way:?
> typedef void (*__sighandler_t) (int);
We define that any signal handling function doesn't return anything
useful (void, that is), and all these functions get a single argument
(of type int) supplied.
> and then, what does this definition mean:
> #define SIG_IGN ((__sighandler_t) 1)
Also, we don't want *all* signals to actually be handled. Some are to be
ignored. Since we can only use function pointers (now of type
__sighandler_t), we need to have a special magic value (1 in this case)
that we can use.
However, "1" alone doesn't make a good function pointer, nor is it a
function at all or does accept arguments. To "look" like a function
pointer of correct type, "1" is casted to be of __sighandler_t.
There would have been another approach: we could have written a small
function that does nothing and could be used instead. However, it's
address could change, so it doesn't work well as an API. This is why
instead a distenct value (1) is used instead.
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: anything to do with pointer to functions maybe?
2004-12-23 11:47 ` Jan-Benedict Glaw
@ 2004-12-23 14:19 ` soraberri
0 siblings, 0 replies; 4+ messages in thread
From: soraberri @ 2004-12-23 14:19 UTC (permalink / raw)
To: linux-c-programming
Jan-Benedict Glaw wrote:
> On Thu, 2004-12-23 11:24:39 +0100, soraberri <421246@posta.unizar.es>
> wrote in message <cqe6ed$ldf$1@sea.gmane.org>:
>
>>Hi all!
>>I'm having troubles understanding code:
>>
>>what type is __sighandler_t if it is defined this way:?
>>typedef void (*__sighandler_t) (int);
>
>
> We define that any signal handling function doesn't return anything
> useful (void, that is), and all these functions get a single argument
> (of type int) supplied.
>
>
>>and then, what does this definition mean:
>> #define SIG_IGN ((__sighandler_t) 1)
>
>
> Also, we don't want *all* signals to actually be handled. Some are to be
> ignored. Since we can only use function pointers (now of type
> __sighandler_t), we need to have a special magic value (1 in this case)
> that we can use.
>
> However, "1" alone doesn't make a good function pointer, nor is it a
> function at all or does accept arguments. To "look" like a function
> pointer of correct type, "1" is casted to be of __sighandler_t.
>
> There would have been another approach: we could have written a small
> function that does nothing and could be used instead. However, it's
> address could change, so it doesn't work well as an API. This is why
> instead a distenct value (1) is used instead.
>
> MfG, JBG
>
Thanks Jan, I think I have understood...
regards and have happy days
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: anything to do with pointer to functions maybe?
2004-12-23 10:24 anything to do with pointer to functions maybe? soraberri
2004-12-23 11:47 ` Jan-Benedict Glaw
@ 2004-12-30 11:26 ` Glynn Clements
1 sibling, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2004-12-30 11:26 UTC (permalink / raw)
To: soraberri; +Cc: linux-c-programming
soraberri wrote:
> I'm having troubles understanding code:
>
> what type is __sighandler_t if it is defined this way:?
> typedef void (*__sighandler_t) (int);
Pointer to function taking an int argument and returning void.
C's type syntax uses the same grammatical structure as expressions, so
the above is interpreted as saying that the expression:
(*__sighandler_t) (int)
has type "void".
The syntax <expr>(<args>) indicates a function call where the function
is <expr> and the arguments are <args>, so:
(*__sighandler_t) (int)
is a function call where (*__sighandler_t) is the function and the
arguments consist of a single integer. Coupled with the knowledge that
the overall type is "void", the expression:
(*__sighandler_t)
must be a function taking an integer argument and returning void.
If an expression *P has type T then the type of P is "pointer to T",
so __sighandler_t must be a pointer to a function taking an integer
argument and returning void.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-12-30 11:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-23 10:24 anything to do with pointer to functions maybe? soraberri
2004-12-23 11:47 ` Jan-Benedict Glaw
2004-12-23 14:19 ` soraberri
2004-12-30 11:26 ` Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).