typedef-ing an array
Chris Torek
chris at mimsy.umd.edu
Fri Jul 20 13:07:29 AEST 1990
Although I already followed up to the original question, I should
correct something here:
In article <1990Jul3.231408.14315 at everexn.uucp> roger at everexn.uucp
(Roger House) writes:
>... The string "Silly old me" is of type "pointer to char".
The type of a string constant is `array N of char', where N is one more
than the number of characters in the string% (the extra one is for the
final '\0' character). In this case the type is `array 13 of char'. The
string was, however, in a value context and as such undergoes the
usual transformation:
In any value context, an object of type `array N of T' becomes a
value of type `pointer to T' whose value is the address of the
first (0th) element of the array.
This rule is extremely important. Like the rule `a*b = b*a', it must
simply be memorised as a Fact Of C. Given that and the rules of pointer
arithmetic and indirection, you can derive a consistent method for
dealing with arrays and pointers.
-----
% I am intentionally ignoring multibyte strings here, as they mainly
serve to confuse the issue.
>In C you cannot assign a value to an array by using the assignment
>operator "=".
This is correct: an array is not a modifiable lvalue (i.e., it may not
be assigned to). Note that an initialization (e.g., char x = 'f';)
is not an assignment (under ANSI X3.159-1989 at least; in Classic C
automatic initializers were semantically identical to assignments,
but under New C aggregates are permitted here).
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list