有没有办法在ANSI C中打印指向函数的指针?当然这意味着你必须将函数指针强制转换为void指针,但似乎不可能?
#include <stdio.h>
int main() {
int (*funcptr)() = main;
printf("%p\n", (void* )funcptr);
printf("%p\n", (void* )main);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
$ gcc -ansi -pedantic -Wall test.c -o test
test.c:在函数'main'中:
test.c:6:警告:ISO C禁止将函数指针转换为对象指针类型
test.c:7:warning :ISO C禁止将函数指针转换为对象指针类型
$ ./test
0x400518
0x400518
它"工作",但非标准...