什么C防爆Ex pression((无效(*)(无效))0)();意思? [英] What does C expression ((void(*)(void))0)(); mean?
问题描述
((无效(*)(无效))0)();
因此,我们有整数0类型转换到这一棘手键入(无效(*))(无效)
,然后执行它。消息来源称,这应该工作,但是它实际上?
So we have integer 0 type casting to this tricky type (void(*))(void)
and then executing it. Source claims that this should work, but what does it actually?
这必须是与C的笑话,比如的#define TRUE FALSE之一
,我想。
This must be one of those C jokes like #define TRUE FALSE
, I suppose.
推荐答案
这是一个期待的功能没有参数和返回值无:
This is a function expecting no arguments and returning no value:
void f(void)
这是一个指向一个函数期待任何参数和返回值无:
This is a pointer to a function expecting no arguments and returning no value:
void (*p)(void)
这是键入的那个指针:
void (*)(void) /* just remove the p! */
这是该类型在括号:
(void (*)(void))
这是一个浇铸到该类型(括号中的类型,后面的值):
This is a cast to that type (the type in parentheses, followed by a value):
(void (*)(void))0
还是和我在一起?到目前为止,我们已经将整数值0转换为指针到功能 - 即通吃无参数和-收益全无。
Still with me? so far we have the integer value 0 cast to a pointer-to-function-that-takes-no-arguments-and-returns-nothing.
演员是指针到函数型的前pression。当你有一个的话你可以这样调用它:
The cast is an expression with pointer-to-function type. When you have one of those you can call it like this:
(your expression here)(arguments to the function)
第一组括号只是为precedence,有时可能不需要(但这次他们)。最终结果是:
The first set of parentheses are just for precedence, and sometimes might not be needed (but this time they are). The end result:
((void (*)(void))0)(/* no args */);
取值0,将其转换为指针到函数期待,无参数,和返回全无,并调用它,提供没有参数。
Takes the value 0, casts it to pointer-to-function-expecting-no-arguments-and-returning-nothing, and calls it, supply no arguments.
这篇关于什么C防爆Ex pression((无效(*)(无效))0)();意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!