相关疑难解决方法(0)

如何格式化函数指针?

有没有办法在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

它"工作",但非标准...

c function-pointers

44
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×1

function-pointers ×1