- 论坛徽章:
- 0
|
本帖最后由 davelv 于 2010-12-24 11:43 编辑
C89要求定义数组时,数组的尺寸必须是整数类型常量表达式
C99则可以是变量
实际上这种数组的尺寸并不是可 ...
KBTiller 发表于 2010-12-22 22:30
sizeof()对VLA运算的时候,是属于运行时计算,这点ISO手册也有提及,也就是说,长度可变。
当然在对象的生命周期内是长度固定的,但这点无论是翻译成变长数组还是翻译成变量长度数组,都可能会引起歧义,都要提及的,或者提前统一说明:C语言任何类型的对象的长度(sizeof)在对象的生命周期内大小不变(不知道我这句话对不对,大家可以挑刺)。
6.5.3.4 The sizeof operator
2.The sizeof operator yields the size (in bytes) of its operand, which may be an
expression or the parenthesized name of a type. The size is determined from the type of
the operand. The result is an integer. If the type of the operand is a variable length array
type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an
integer constant. |
|