*/ } ul /* Whole unordered list */ { } ul li /* Unordered list item */ { } ol /* Whole ordered list */ { } ol li /* Ordered list item */ { } hr {} /* ---- Some span elements --- */ sub /* Subscripts. Pandoc: H~2~O */ { } sup /* Superscripts. Pandoc: The 2^nd^ try. */ { } em /* Emphasis. Markdown: *emphasis* or _emphasis_ */ { } em > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > p > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > * > p > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > p > ins > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > * > p > ins > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } /* ---- Links (anchors) ---- */ a /* All links */ { /* Keep links clean. On screen, they are colored; in print, they do nothing anyway. */ text-decoration: none; } @media screen { a:hover { /* On hover, we indicate a bit more that it is a link. */ text-decoration: underline; } } @media print { a { /* In print, a colored link is useless, so un-style it. */ color: black; background: transparent; } a[href^="http://"]:after, a[href^="https://"]:after { /* However, links that go somewhere else, might be useful to the reader, so for http and https links, print the URL after what was the link text in parens */ content: " (" attr(href) ") "; font-size: 90%; } } /* ---- Images ---- */ img { /* Let it be inline left/right where it wants to be, but verticality make it in the middle to look nicer, but opinions differ, and if in a multi-line paragraph, it might not be so great. */ vertical-align: middle; } div.figure /* Pandoc figure-style image */ { /* Center the image and caption */ margin-left: auto; margin-right: auto; text-align: center; font-style: italic; } p.caption /* Pandoc figure-style caption within div.figure */ { /* Inherits div.figure props by default */ } /* ---- Code blocks and spans ---- */ pre, code { background-color: #fdf7ee; /* BEGIN word wrap */ /* Need all the following to word wrap instead of scroll box */ /* This will override the overflow:auto if present */ white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ /* END word wrap */ } pre /* Code blocks */ { /* Distinguish pre blocks from other text by more than the font with a background tint. */ padding: 0.5em; /* Since we have a background color */ border-radius: 5px; /* Softens it */ /* Give it a some definition */ border: 1px solid #aaa; /* Set it off left and right, seems to look a bit nicer when we have a background */ margin-left: 0.5em; margin-right: 0.5em; } pre.yacc, code.yacc { background-color: #f0f0f0; } pre.yacc /* Code blocks */ { /* Distinguish pre blocks from other text by more than the font with a background tint. */ padding: 0.0em; /* Since we have a background color */ border-radius: 5px; /* Softens it */ /* Give it a some definition */ border: 0px solid #aaa; /* Set it off left and right, seems to look a bit nicer when we have a background */ margin-left: 0.0em; margin-right: 0.0em; } @media screen { pre { white-space: pre; /* Dotted looks better on screen and solid seems to print better. */ border: 1px dotted #777; } } code /* All inline code spans */ { } p > code, li > code /* Code spans in paragraphs and tight lists */ { /* Pad a little from adjacent text */ padding-left: 2px; padding-right: 2px; } li > p code /* Code span in a loose list */ { /* We have room for some more background color above and below */ padding: 2px; } span.option { color: blue; text-decoration: underline; } /* ---- Math ---- */ span.math /* Pandoc inline math default and --jsmath inline math */ { /* Tried font-style:italic here, and it messed up MathJax rendering in some browsers. Maybe don't mess with at all. */ } div.math /* Pandoc --jsmath display math */ { } span.LaTeX /* Pandoc --latexmathml math */ { } eq /* Pandoc --gladtex math */ { } /* ---- Tables ---- */ /* A clean textbook-like style with horizontal lines above and below and under the header. Rows highlight on hover to help scanning the table on screen. */ table { border-collapse: collapse; border-spacing: 0; /* IE 6 */ border-bottom: 2pt solid #000; border-top: 2pt solid #000; /* The caption on top will not have a bottom-border */ /* Center */ margin-left: auto; margin-right: auto; } thead /* Entire table header */ { border-bottom: 1pt solid #000; background-color: #eee; /* Does this BG print well? */ } tr.header /* Each header row */ { } tbody /* Entire table body */ { } /* Table body rows */ tr { } tr.odd:hover, tr.even:hover /* Use .odd and .even classes to avoid styling rows in other tables */ { background-color: #eee; } /* Odd and even rows */ tr.odd {} tr.even {} td, th /* Table cells and table header cells */ { vertical-align: top; /* Word */ vertical-align: baseline; /* Others */ padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.2em; padding-bottom: 0.2em; } /* Removes padding on left and right of table for a tight look. Good if thead has no background color*/ /* tr td:last-child, tr th:last-child { padding-right: 0; } tr td:first-child, tr th:first-child { padding-left: 0; } */ th /* Table header cells */ { font-weight: bold; } tfoot /* Table footer (what appears here if caption is on top?) */ { } caption /* This is for a table caption tag, not the p.caption Pandoc uses in a div.figure */ { caption-side: top; border: none; font-size: 0.9em; font-style: italic; text-align: center; margin-bottom: 0.3em; /* Good for when on top */ padding-bottom: 0.2em; } /* ---- Definition lists ---- */ dl /* The whole list */ { border-top: 2pt solid black; padding-top: 0.5em; border-bottom: 2pt solid black; } dt /* Definition term */ { font-weight: bold; } dd+dt /* 2nd or greater term in the list */ { border-top: 1pt solid black; padding-top: 0.5em; } dd /* A definition */ { margin-bottom: 0.5em; } dd+dd /* 2nd or greater definition of a term */ { border-top: 1px solid black; /* To separate multiple definitions */ } /* ---- Footnotes ---- */ a.footnote, a.footnoteRef { /* Pandoc, MultiMarkdown footnote links */ font-size: small; vertical-align: text-top; } a[href^="#fnref"], a.reversefootnote /* Pandoc, MultiMarkdown, ?? footnote back links */ { } @media print { a[href^="#fnref"], a.reversefootnote /* Pandoc, MultiMarkdown */ { /* Don't display these at all in print since the arrow is only something to click on */ display: none; } } div.footnotes /* Pandoc footnotes div at end of the document */ { } div.footnotes li[id^="fn"] /* A footnote item within that div */ { } table tr td,th { border-right: 1px solid; border-left: 1px solid; } /* You can class stuff as "noprint" to not print. Useful since you can't set this media conditional inside an HTML element's style attribute (I think), and you don't want to make another stylesheet that imports this one and adds a class just to do this. */ @media print { .noprint { display:none; } }
2024-12-01
integration into IS ISO/IEC 9899:202y
document number | date | comment |
---|---|---|
n3393 | 202411 | Original proposal |
n3414 | 202412 | Motivate the two proposed normative changes |
Use the term “number of elements” | ||
Only refer to the different syntaxt rules as “forms” | ||
Make it clearer that only one of the conditions for composite types is syntactic |
CC BY, see https://creativecommons.org/licenses/by/4.0
The current wording of 6.7.7.3 is very confusing because it mixes up
syntactic and semantic definitions in several places. In particular it
introduces a term “size of an array” in the constraints section that is
not properly defined; it is not clear what “specifies” means here. Later
in the text even the case of a *
token, which is
just one other syntax derivation, is seemingly subsumed with that term.
So is it a syntax element (the assignment expression or *
token) or is it a
semantic derivation (the value of that assignment expression, which does
not exist for the *
case)?
We propose to iron out these issues by changing the text to use already introduced terms and to make a clearer distinction of where the text talks about syntactic deduction and where it introduces semantic for that syntax.
We remove the confusing term “size of an array” by reverting its use to the one that appears in the syntax derivation, namely an assignment expression. Adding just this distinctive word in all places where the current text just talks about “expression”, should make things clearer.
In particular when it comes to the definition of compatible types, the current text gives a definition that only applies sensibly to the syntactic constructs, and that lack a consistent lift to the semantics. So we change this definition of compatibility to refer to the syntax construct “array declarator” (which is the subject of the clause) and only then lift this definition to array types in a second step.
We propose two normative changes which are not meant to change existing practice but to repair the standard such it matches existing practice. If any of these normative changes is not wanted by WG14, it can easily be omitted.
The addition of the word integer in some places upgrading the term “constant expression” to “integer constant expression” (6.7.7.3 and J .2 item 72) is intended to be a normative change.
Discussion on the reflector has shown that the expressions here are meant to reflect a constraint at translation time and not a link time, and so we propose to rectify the text by this addition.
A change of semantics also occurs in 6.7.11 when changing the term “initializer list” to “initializer or braced initializer”. This is doubly motivated
We also add “or by an initializer” in 6.2.5 p27, because without this the description is incomplete. The type of an identifier can be completed within the same definition, not only by additional declarations that have linkage that are provided later. Note that here adding “initializer” and not “braced initializer” is sufficient because that sentence is talking of declarations of identifiers. This addition does not change the normative contents of the text.
New text is underlined green, removed text is
stroke-out red.
27 An array type of unknown
sizenumber of elements is an incomplete type. It is completed, for an identifier of that type, by specifying the size in a later declaration (with internal or external linkage) or by an initializer, see 6.7.11. A structure or union type of unknown content (as described in 6.7.3.4) is an incomplete type. It is completed, for all declarations of that type, by declaring the same structure or union tag with its defining content later in the same scope.
in p3, second bullet
- If both types are array types, the following rules are applied:
- If one type is an array of known constant size and N elements, the composite type
is an array of that sizehas N elements.- Otherwise, if one type is a variable length array whose
size is specified by andeclarator has an assignment expression that is not evaluated, the behavior is undefined.- Otherwise, if one type is a variable length array
whose size is specifiedwith N elements, the composite type is a variable length arrayof that sizewith N elements.- Otherwise, if one type is a variable length array
of unspecified sizewith an unspecified number of elements, the composite type is a variable length arrayof unspecified sizewith an unspecified number of elements.- Otherwise, both array types are incomplete
arrays of unknown sizeand the composite type is an incomplete arrayof unknown sizetype.
Constraints
1 In addition to optional type qualifiers and the keyword
static
, the[
and]
can delimit an assignment expression or a*
token. If they delimit an assignment expression(which specifies the size of an array), the expressionit shall have an integer type. If the assignment expression is an integer constant expression, it shall have a value greater than zero. The element type shall not be an incomplete or function type. The optional type qualifiers and the keywordstatic
shall appear only in a declaration of a function parameter with an array type, and then only in the outermost array type derivation.
2 …
Semantics
3 …
4
If the size is not presentIn the first form, the array type has an unknown number of elements and is an incomplete type.If the size is * instead of being an expressionIn the fourth form, the array type is a variable length array typeof unspecified sizewith an unspecified number of elements, which can only be used as part of the nested sequence of declarators or abstract declarators for a parameter declaration, not includinganything inside an array size expressionany array declarator of the second or third form in one of those declarators;161) such arrays are nonetheless complete types. Otherwise, if the assignment expression is evaluated its value is the number of elements of the array type (6.2.5); this value is subsequently also denoted by the terms size of an array or length of an array. If thesizeassignment 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; otherwise, the array type is a variable length array type. (Variable length arrays with automatic storage duration are a conditional feature that implementations may support; see 6.10.10.4.)
5 If the
size is anassignment expressionthatis not an integer constant expression: if it occurs in a declaration at function prototype scope, it is treated as if it were replaced by a*
token; otherwise, each time it is evaluated it shall have a value greater than zero. Thesizenumber of elements of each instance of a variable length array type does not change during its lifetime. Wherea sizethe assignment expression is part of the operand of a typeof orsizeof
operator and changing the value of thesizeassignment expression would not affect the result of the operator, it is unspecified whether or not thesizeassignment expression is evaluated. Wherea sizean assignment expression is part of the operand of analignof
operator, that assignment expression is not evaluated.
6 For two array types to be compatible, both shall have compatible element types, and if
both size specifiers are present, and are integer constant expressions, then both size specifiers shall have the same constant valuefor both the number of elements is specified, it shall be the same .If the two array types are used in a context which requires them to be compatible, the behavior is undefined if the two size specifiers evaluate to unequal values.
…
11 EXAMPLE 5 The following is invalid, because the use of
[*]
is inside anarray sizeassignment expression of and array declarator rather than directly part of the nested sequence of abstract declarators for a parameter declaration:
3 In a declaration whose storage-class specifier is
typedef
, each declarator defines an identifier to be a typedef name that denotes the type specified for the identifier in the way described in 6.7.7. Anyarray sizeassignment expressions associated with variable length array declarators and typeof operators are evaluated each time the declaration of the typedef name is reached in the order of execution. Atypedef
declaration does not introduce a new type, only a synonym for the type so specified. That is, in the following declarations: …
23 If an array of
unknown sizean incomplete array type is initialized, itssizenumber of elements is determined by the largest indexed element with an explicit initializer. The array type is completed at the end of its initializerlist(for array definitions) or braced initializer (for compound literals).
4 A full expression is an expression that is not part of another expression, nor part of a declarator or abstract declarator. There is also an implicit full expression in which
the non-constant sizean assignment expressionsfor a variably modified typeof an array declarator that is not an integer constant expression are evaluated; within that full expression, the evaluation of differentsizeassignment expressions of array declarators are unsequenced with respect to one another. There is a sequence point between the evaluation of a full expression and the evaluation of the next full expression to be evaluated.
In p4 make the following change
Here, the
static
array sizeadorned assignment expression of the array declarator and the annotation of the control flow withunreachable
indicates that the pointed-to parameter arrayargv
will hold at least three elements, regardless of the circumstances.
- Whether
a size expressionan assignment expression of an array declarator is evaluated when it is part of the operand of a sizeof operator and changing the value of thesizeassignment expression would not affect the result of the operator (6.7.7.3)
- A program requires the formation of a composite type
from a variable length array type whose size is specified by anfrom an array declarator with an assignment expression that is not evaluated (6.2.7).
- The
size expression in an array declarationassignment expression of an array declarator is notaan integer constant expression and evaluates at program execution time to a nonpositive value (6.7.7.3).
- In a context requiring two array types to be compatible, they do not have compatible element types, or
their size specifiers evaluate to unequal valuestheir respective number of elements are specified but are not the same (6.7.7.3).
If n3415 is accepted concurrently, the additions of the word “assignment” above should instead read “reproducible”. Note that n3416 also proposes changes to 6.7.7.3, but that these are independent of each other.
Thanks to Jakub Łukasiewicz, Javier Múgica and Robert Seacord for review and discussions.