c - APUE 10.3 signal: pointer cast issue. -
i learning apue 10.3 signal, , confusing define of sig_err, sig_dfl , sig_ign. here definition:
#define sig_err (void (*)())-1 #define sig_dfl (void (*)())0 #define sig_ign (void (*)())1 and here signal function prototype:
void (*signal(int signo, void (*func)(int)))(int) when call signal(signo, sig_dfl), why there no function mismatch issue since 2nd parameter should void (*)(int)), however, provided sig_dfl type of (void (*)()), void (*)(int)) vs (void (*)()) ?
a function declared : type function() means don't specify parameters of function, can call function parameters or none. in fact, tells compiler ignore type-checking parameters of function, since don't use them. proper way declare function no parameters type function(void).
so, in fact, when type checking void (*)()) against void (*)(int)), compiler checks return value type.
note isn't true in c++, in c. in c++, type function() equivalent type function(void).
you can check out official c99 specification here. function definitions @ 6.9.1, page 141.
Comments
Post a Comment