WG14 Document Number: N893

Date: 15-Sept-1999

Defect Report #99-XXX

Submission Date: 15 Sept 1999
Submittor: Raymond Mak (Canada C Working Group)
Source: Canada C Working Group

Question
size_t and ptrdiff_t can now be a long long type, which is not necessary for hardwares that do not support 64-bit addressing. Implementors should be encouraged to choose a type for these two that minimizes compatibility problems to existing (32-bit) code.

Suggested Correction
In 7.17 at the end of p2, add the following :

Recommended Practice

The long long type should be used only if no other integer types can represent the value range required by the implementation.

Defect Report #99-XXX

Submission Date: 15 Sept 1999
Submittor: Raymond Mak (Canada C Working Group)
Source: Canada C Working Group

Question
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.

Suggested Correction
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 occurences of static to __at_least):

direct_declarator :
identifier
( declarator )
direct-declarator [ type-qualifier-list assignment-expression ]
direct-declarator [ __at_least assignment-expression type-qualifier-list ]
direct-declarator [ type-qualifier-list __at_least assignment-expression ]
... (the rest is the same as in the FIDS) ...

Change 6.7.5.2p1 to (i.e. the two occurences of static to __at_least) :

[#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 6.7.5.2p3 to (i.e. the three occurences of static to __at_least, and bind __at_least with assignment-expr in the syntax) :


D[ type-qualifier-list-opt assignment-expr-opt ]
D[ __at_least assignment-expr type-qualifier-list-opt ]
D[ type-qualifier-list __at_least assignment-expr ]
D[ type-qualifier-list-opt * ]

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 6.7.5.3 for the meaning of the optional type qualifiers and the keyword __at_least.)

Change 6.7.5.3p7 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 6.7.5.3p21 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)[5]);
void f(double a[restrict][5]);
void f(double a[restrict 3][5]);
void f(double a[restrict __at_least 3][5]);
...

Change A.1.2 to add keyword :

__at_least

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 interfer 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 ] becomes the qualifier for the pointer. If '__at_least assignment-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 6.7.5.3p7 become unecessary. 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. ------------------------------------------------------------------------------