- 论坛徽章:
- 17
|
回复 1# zheguzai
这本来是个错误的语法,是标准所不允许的,但是gcc的扩展允许此用法。
c标准中对sizeof有如下规定:6.5.3.4
The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression that designates a bit-field member.
根据上述规定定function type是不被允许的。
gcc的有如下所述的扩展:
5.17 Arithmetic on void- and Function-Pointers
In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1.
A consequence of this is that sizeof is also allowed on void and on function types, and returns 1.
The option -Wpointer-arith requests a warning if these extensions are used.
https://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Pointer-Arith.html#Pointer-Arith
可见之所以返回1是由于gcc的扩展影响的结果。 |
|