Keith said:
That's not what the code is trying to do. p is a function pointer,
but &p is an object pointer (it points to the function pointer). The
code, if I recall correctly, decomposes the representation of the
function pointer to a sequence of bytes to be printed. The results
are implementation-defined, but it's legal, and it's the only portable
way to print (a representation of) the value of a function pointer.
Amazingly enough, it works here, if you will put up with some digit
jumbling, and lack of knowledge of the size involved.
[1] c:\c\junk>cat junk.c
#include <stdio.h>
int return10(void) {return 10;}
int main(int argc, char ** argv)
{
int (*f)(void) = return10;
unsigned char *p = (unsigned char *)&f;
int i, n;
char hex[] = "0123456789abcdef";
for (i = 0; i < 4; i++) {
n = *(p + i);
putchar(hex[(n & 0xf0) >> 4]);
putchar(hex[(n & 0x0f)]);
}
putchar('\n');
return 0;
} /* main */
[1] c:\c\junk>cc junk.c
junk.c: In function `main':
junk.c:5: warning: unused parameter `argc'
junk.c:5: warning: unused parameter `argv'
[1] c:\c\junk>.\a
30160000
[1] c:\c\junk>objdump -dS a.exe | grep return10
00001630 <_return10>:
int return10(void) {return 10;}
int (*f)(void) = return10;