Standard C - Volume 1, No. 1
The Moderator
osd7 at homxa.UUCP
Wed Oct 31 23:24:30 AEST 1984
**************** mod.std.c vol. 1 no. 1 ***************************
Mail your ideas and replies to the author(s) below or to cbosgd!std-c.
Cbosgd is reachable via most of the USENET nodes, including ihnp4,
ucbvax, decvax, hou3c.... Administrivia should be mailed to
cbosgd!std-c-request
----------------------------------------------------------------------
Date: Mon, Oct. 29
From: hpdsa!decot (Dave Decot)
Subject: Array proposals
Proposal to add aggregate constants to C. Proposals to add array lvalues,
assignment, comparison, parameters, and return values to C.
I. AGGREGATE CONSTANTS AND AUTOMATIC AGGREGATE INITIALIZATION
Each of the constructions
{ initializer-list }
and
{ initializer-list , }
is a constant and an expression of type "aggregate". Only constants may
have this type; there is no type-specifier for it. The only operations
permitted on values of type "aggregate" are
assignment to objects which are structures, unions, or arrays; and
casting to types which are structures, unions, or arrays.
Such assignments and casts are permitted only where the expression would
be acceptable as an initializer to an external or static variable of the
cast or assignment's destination type. If initialization of unions is
not permitted, then neither are assignments or casts of these
values to types which are or contain unions.
The result of a cast of an aggregate to a structure, union or array
type is the initial value of the hypothetical initialized extern or
static variable.
An assignment of an aggregate to a variable causes the aggregate to be
cast to the type of the variable, and the resulting value to be
assigned to the variable.
Initialization of automatic struct, union, and array variables is permitted,
with a syntax similar to that for static ones. The initialization occurs
upon each entry to the function or block containing it, and the same value
is assigned every time.
(This could be implemented by keeping a static copy of a value around,
and copying the entire block of memory to the allocated stack space upon
entry to the function or block.)
Note that when a string in double quotes appears in the initializer for
automatic aggregate variables, its type may be 'pointer to char' or 'array
of char', depending on the type of the associated part of the destination
type. Even if the type is 'pointer to char', the string pointed to by
that part of the initial value is the same each time it is executed,
and is not affected by changes to previous instances of the string.
(This could be implemented by allocating the extra space needed for such
strings with the rest of the aggregate value on the stack, and
assigning a pointer to the space to that part of the value after copying
the value.)
II. ARRAY LVALUES
In order to form an lvalue which is an array, the syntax for lvalue
(K&R C Reference Manual 18.1) is extended as follows:
lvalue:
primary []
The primary must generate a variable whose type is "array of ...",
and the size of the array must be determinable at compile time.
The lvalue refers to the entire array. It is impossible to construct
a declaration that causes an identifier unadorned by '[]' to imply this
reference. Subscripts appended to array lvalues (e.g., a[][3]) are not
allowed, nor may the -> or . operators be applied. "[]" has the same
precedence as the subscripting operator.
An primary for a multidimensional array with at least one appended '[]'
pair, but fewer pairs than the number of dimensions, refers to the same
array as would the same primary followed by the same number of pairs
as dimensions. There may not be more '[]' pairs than dimensions, however.
For example, if array a is declared as
int a[13][5];
then
a[6][] refers to the entire seventh member ("row") of array a
a[] refers to the entire array a
a[][] refers to the entire array a
a[][][] is illegal.
IIa. ARRAY ASSIGNMENTS, POINTERS, AND CASTS
An array lvalue may be the destination of assignments. Its address
may be taken by prepending a '&'. The resulting type is different from
that of the name of the array alone, since the latter is only a pointer
to the first element of the array, and not a pointer to the array itself.
Abstract declarators for array types are already defined by the language;
they can be used to designate target array types in casts if the
constant-expression between the brackets is present.
Casts and assignments to array types where the type of array elements
and number of dimensions are the same, but the number of elements
in the source and destination types differ, are allowed, and
are performed by truncating the source value on the right or padding the
value on the right with 0. For any other cast or assignment from an
array type, the source and destination types must be exactly the same.
IIb. ARRAY PARAMETERS
Array expressions may be used as value parameters to functions, but all
dimensions of such arrays must be supplied in their formal parameter
declaration, so that the size of the array is calculable during
compilation. (Should array formal parameters with typedef type names
be passed by reference?)
Although this formal parameter syntax was previously allowed (the leftmost
dimension was ignored and the type was assumed to be "pointer to element"),
this change results in no loss of functionality. It may cause older
programs which supplied this ignored dimension to break, since the types
are different. This problem would be caught by lint.
IIc. ARRAY-VALUED FUNCTIONS
Functions may return array types; the size must be specified as a
constant expression inside the brackets of the function header declarator.
IId. ARRAY COMPARISON
An array type is _comparable_ if the type of the array elements is
one of the arithmetic types, or an enum type, or a comparable array type.
The relational operators (==, !=, <, <=, >, and >=) may be applied to
two array values if they are of the same, comparable, array type.
The value of the comparison is computed by comparing (in order) each
of the elements of the first array to the associated element of the
second. If the elements differ, the comparison stops and the value
is that of the relational operator applied to the two elements.
If the arrays are identical, the value is that of the relational operator
applied to the last two elements.
Dave Decot
ihnp4!ucbvax!hpda!decot
Hewlett-Packard Company, Data Systems Division
--------------------------------------
End of Vol. 1, No. 1. Std-C (Oct. 31, 1984 08:00:00 EST)
--
Orlando Sotomayor-Diaz/AT&T Bell Laboratories/201-870-7249
/Crawfords Crnr. Rd., Holmdel WB 3D109, NJ, 07733
UUCP: {ihnp4, houxm, akgua, mhuxd, ...}!homxa!osd7
More information about the Mod.std.c
mailing list