Jens Gustedt, INRIA and ICube, France
2024年11月17日
integration into IS ISO/IEC 9899:202y
| document number | date | comment |
|---|---|---|
| n3391 | 202411 | Original proposal |
It seems that the current terminology that is applied for variable length arrays (VLA) and variably modified types (VM types) is often misunderstood because the term "variable length array type" is introduced quite confusingly spread over the text and by applying double negation. We think that the dual term, "complete type with known constant size", is much easier to introduce consistently.
The goal of this papers to strictly define the term "complete type with known constant size" recursively. VLA then are just "complete array types for which the size is not known during translation".
This is not intended to change semantics of the text.
Whether or not we then keep up the term VLA (to which people are accustomed) and whether or not we use size/length/extend/count... is of secondary interest and could be done in a second phase.
New text is (追記) underlined green (追記ここまで), removed text is
(削除) stroke-out red (削除ここまで).
6 For such an object that does
(削除) not have a variable length array type (削除ここまで)(追記) have a known constant size, see 6.2.5 (追記ここまで), its lifetime extends from entry into the block with which it is associated until execution of that block ends in any way. (Entering an enclosed block or calling a function suspends, but does not end, execution of the current block.) If the block is entered recursively, a new instance of the object is created each time. The initial representation of the object is indeterminate. If an initialization is specified for the object and it is not specified withconstexpr, it is performed each time the declaration or compound literal is reached in the execution of the block; if it is specified withconstexprthe initializer is evaluated once at translation time and the new instance of the object is initialized to that fixed value each time the specification is reached; otherwise, the representation of the object becomes indeterminate each time the declaration is reached.
7 For such an object that does
(削除) have a variable length array type (削除ここまで)(追記) not have a known constant size (追記ここまで), its lifetime extends from the declaration of the object until execution of the program leaves the scope of the declaration.26) If the scope is entered recursively, a new instance of the object is created each time. The initial representation of the object is indeterminate.
28 A complete type shall have a size that is less than or equal to SIZE_MAX.
(削除) A type has known constant size if it is complete and is not a variable length array type. (削除ここまで)(追記) A complete type has a known constant size if it is not a derived type or if it is a pointer, atomic, structure, or union type; for array types specific rules apply to determine if they have known constant size, see 6.7.7.3. (追記ここまで)
sizeof and alignof
operators2 The
sizeofoperator yields the size (in bytes) of its operand, which can 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 (削除ここまで)(追記) does not have a known constant size (追記ここまで), the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant expression.
3 A structure or union shall not contain a member
(削除) with incomplete or function type (削除ここまで)(追記) that does not have a known constant size (追記ここまで) (hence ...
Note to the editors: It might be good to profit from the change to transform the weird subsentences in parenthesis that are obviously not meant to be part of the normative text into footnotes.
...
11 A member of a structure or union can have any
(削除) complete object type (削除ここまで)(追記) type of known constant size (追記ここまで) other than a variably modified type.132) ...
4 If the size is not present, the array type is an incomplete type. If the size is
*instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used as part of the nested sequence of declarators or abstract declarators for a parameter declaration, not including anything inside an array size expression in one of those declarators;161) such arrays are nonetheless complete types. If the size (追記) expression (追記ここまで) is an integer constant expression and the element type has a known constant size,(削除) the array type is not a variable length array type (削除ここまで)(追記) the array type has a known constant size (追記ここまで); otherwise, the array type is a variable length array type.(追記) FNT) (追記ここまで)
(追記) FNT) (追記ここまで)
(削除) (Variable length arrays with (削除ここまで)(追記) Arrays that do not have a known constant size and that have (追記ここまで) automatic storage duration are a conditional feature that implementations may (追記) not (追記ここまで) support; see 6.10.10.4.(削除) ) (削除ここまで)
__STDC_NO_VLA__The integer literal1, intended to indicate that the implementation does not support(削除) variable length arrays with (削除ここまで)(追記) arrays that do not have a known constant size and that have (追記ここまで) automatic storage duration. Parameters declared with variable length array types are adjusted and then define objects of automatic storage duration with pointer types. Thus, support for such declarations is mandatory.
Note that n3393 also proposes changes to 6.7.7.3, but that these are independent of each other.