Is there a recommended integer type to store function pointers in standard C
The C99 standard has uintptr_t, a recommended integer type to convert data
pointers (pointers to objects) to, but I did not find an equivalent
integer type to store function pointers. Did I overlook it?
A specific compiler could define such a type even though it is not in the
standard, but a compiler is more likely to state that a function pointer
can be stored in (say) a uint64_t than to define a new type.
Another difference is that it can make sense to do integer arithmetic on a
data pointer in ways that it doesn't on function pointer. One common idiom
is (int*)(((uintptr_t)p + 15) & ~(uintptr_t)15) but there is no reason to
apply this idiom to a function pointer.
No comments:
Post a Comment