c - Subtracting 1 from a function pointer -


i saw line in signal.h in /usr/include/sys/ on mac. based on it's use return type of function signal, i'd expect sig_err pointer function takes integer input , returns void. macro expansion of sig_err seems subtract 1 function pointer type, found weird. how c parse it?

#define sig_err         ((void (*)(int))-1)   

( (void(*)(int)) -1)   

does not subtract 1 function pointer, cast constant value -1 function pointer.

as side note, adding or subtracting function pointer not allowed in iso c , can done as (somewhat peculiar) gcc extension handles if char pointer;

in gcc, addition , subtraction operations allowed on pointers of type void, , pointers functions. normally, iso c not allow arithmetic on such pointers because size of "void" silly concept, , dependent on pointer pointing to. facilitate such arithmetic, gcc treats size of referential object 1 byte.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -