How to format a function pointer?
Posted
by Longpoke
on Stack Overflow
See other posts from Stack Overflow
or by Longpoke
Published on 2010-04-30T00:49:02Z
Indexed on
2010/04/30
0:57 UTC
Read the original article
Hit count: 360
c
Is there any way to print a pointer to a function in ANSI C? Of course this means you have to cast the function pointer to void pointer, but it appears that's not possible??
#include <stdio.h>
int main() {
int (*funcptr)() = main;
printf("%p\n", (void* )funcptr);
printf("%p\n", (void* )main);
return 0;
}
$ gcc -ansi -pedantic -Wall test.c -o test
test.c: In function 'main':
test.c:6: warning: ISO C forbids conversion of function pointer to object pointer type
test.c:7: warning: ISO C forbids conversion of function pointer to object pointer type
$ ./test
0x400518
0x400518
It's "working", but non-standard...
© Stack Overflow or respective owner