- 論壇徽章:
- 17
|
回復(fù) 1# zheguzai
這本來是個(gè)錯(cuò)誤的語(yǔ)法,是標(biāo)準(zhǔn)所不允許的,但是gcc的擴(kuò)展允許此用法。
c標(biāo)準(zhǔn)中對(duì)sizeof有如下規(guī)定: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.
根據(jù)上述規(guī)定定function type是不被允許的。
gcc的有如下所述的擴(kuò)展:
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的擴(kuò)展影響的結(jié)果。 |
|