Reputation: 3364
There's some information about how struct is laid out in memory in a C process. I wanted to know how a function pointer is laid out in memory. e.g.
void (*fun_ptr)(int)
Upvotes: 0
Views: 88
Reputation: 123578
This is entirely a function of the underlying platform. C does not specify the representation of any pointer type, only what its behavior needs to be.
C does specify that object and function pointers are not interchangeable; a void *
can be converted to any object pointer type and vice-versa, and a function pointer type can be converted to any other function pointer type, but converting between object and function pointers may not be allowed (gcc
with the -pedantic
flag will yak if you try to convert a function pointer to void *
or vice-versa).
Pointers may have a simple flat integer representation, or they may be a structured representation like a page number and an offset, or they may be something else. Pointers to different types don't have to have the same size and representation - e.g., a char *
doesn't have to have the same representation as an int *
, which doesn't have to have the same representation as a struct foo *
, etc.
But again, it depends entirely on the platform.
Upvotes: 2