他们说这个表达式在 C 中是有效的,它意味着调用一个函数:
(*(void(*)())0)();
有人能清楚地解释一下这个表达式的意思吗?
我试着编译它,很惊讶它没有导致错误。
最佳答案
一步一步:
void(*)() // a pointer-to-function type, taking unspecified parameters
// and returning nothing.
(void(*)())0 // a null pointer of that pointer-to-function type
(*(void(*)())0) // dereference that pointer
(*(void(*)())0)(); // and call it with no parameters
代码有未定义的行为,它可能会因某种非法访问/段错误而崩溃。
关于c - 解密 (*(void(*)())0)(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2604428/