Submitter: Raymond Mak (Canada C Working Group)
Submission Date: 1999-09-15
Source: Canada C Working Group
Reference Document: ISO/IEC WG14 N893
Date: 2001-09-18 14:27:29
Subject: New keyword __at_least
6.7.5 introduces a new use of the static keyword. A new keyword should be used instead.
This use of static can only occur in function parameter declaration. If we examine the syntax carefully, static assignment-expression taken together inside [ and ] really plays the role of a type qualifier qualifying a pointer. This means the assignment-expression should only be allowed to follow immediately after the keyword static (when static is present), with no other type qualifiers allowed in between. Also, a new keyword should be used to make the meaning clear.
Use a new keyword, __at_least, in place of static.
Change 6.4.1p1 to add a new keyword: __at_least
Change the syntax under 6.7.5 to (the two occurrences of static to __at_least):
direct_declarator :Change 22.214.171.124p1 to (i.e. the two occurrences of static to __at_least):
( declarator )
direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
direct-declarator [ __at_least assignment-expression type-qualifier-listopt ]
direct-declarator [ type-qualifier-listopt __at_least assignment-expression ]
... (the rest is the same as in the FDIS) ...
[#1] In addition to optional type qualifiers and the keyword __at_least, the [ and ] may delimit an expression or *. If they delimit an expression (which specifies the size of an array), the expression shall have an integer type. If the expression is a 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 keyword __at_least shall appear only in a declaration of a function parameter with an array type, and then only in the outermost array type derivation.
Change 126.96.36.199p3 to (i.e. the three occurrences of static to __at_least, and bind __at_least with assignment-expr in the syntax):
D[ type-qualifier-listopt assignment-expropt ]and the type specified for ident in the declaration "T D" is "derived-declarator-type-list T", then the type specified for ident is "derived-declarator-type-list array of T".121) (See 188.8.131.52 for the meaning of the optional type qualifiers and the keyword __at_least.)
D[ __at_least assignment-expr type-qualifier-listopt ]
D[ type-qualifier-list __at_least assignment-expr ]
D[ type-qualifier-listopt * ]
Change 184.108.40.206p7 to (i.e. static to __at_least):
[#7] A declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type", where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword __at_least ...
Change 220.127.116.11p21 to (i.e. static to __at_least):
[#21] EXAMPLE 5 The following are all compatible function prototype declarators.double maximum(int n, int m, double a[n][m]); double maximum(int n, int m, double a[*][*]); double maximum(int n, int m, double a[ ][*]); double maximum(int n, int m, double a[ ][m]);as are:void f(double (* restrict a)); void f(double a[restrict]); void f(double a[restrict 3]); void f(double a[restrict __at_least 3]); ...
Change A.1.2 to add keyword:
Explanation of the change
The new syntax groups '__at_least assignment-expression' together. For example:
double a[restrict __at_least 3] /* ok */
double a[__at_least 3 restrict] /* ok */
double a[__at_least restrict 3] /*not ok */
Conceptually, '__at_least assignment-expression' is a type qualifier. Even though we do not treat it as such in C9X, the potential is there for future enhancement of the language. Therefore we should not interfere with possible future changes in this respect. The following example illustrates the point.
In a function parameter declaration, a parameter of "array of type" is adjusted to "qualified pointer to type". The type-qualifiers inside [ and ] become the qualifier for the pointer. If '__at_leastassignment-expression' is also a type qualifier, this adjustment enables us to write:
int * __at_least(10) p;
which declares a pointer pointing to the first of a sequence of 10 integers in memory. (The parentheses are used for clarity.) The clumsy description in 18.104.22.168p7 become unnecessary. Note that the current static syntax prevents us from writing the equivalent pointer declaration for an array parameter declaration.
This example is presented here only as an illustration of what is possible in the future; it is not meant as a suggested change for this DR. Nevertheless, it does show that allowing other qualifiers appearing between static and the assignment-expression is a conceptual error.
The committee has had several viewpoints on this controversial item. These are ranked with the choice getting the most support first, the last entry getting little or no support.
direct-declarator [ static type-qualifier-listopt assignment-expression ]and change:
direct-declarator [ type-qualifier-list static assignment-expression ]to:
direct-declarator [ type-qualifier-listopt static assignment-expression ]
There is no consensus to make this change or any change along this line.
Previous Defect Report < - > Next Defect Report