Is typedef char BUFFER[20] legal?

Henry Spencer henry at zoo.toronto.edu
Sun Feb 10 11:27:46 AEST 1991


In article <23128 at netcom.COM> avery at netcom.COM (Avery Colter) writes:
>My impression now, preparing my shoulder for more, is that
>typedef is tacked in front of a normal declaration in order
>to have the name treated as the name of a type rather than
>the name of an object, and that declaring a variable of the
>derived type is equivalent to making a non-typedef declaration
>exactly like that to which typedef was prepended, only with
>the new variable name occurring exactly where the derived
>type name was in the typedef declaration.

Essentially correct; your shoulder can relax :-).  The one small addendum
I would make is that there are a few circumstances which can arise only
through the use of typedefs, because they are syntactically impossible
in normal declarations.  For example:

	typedef int a_t[10];
	const a_t a;

attempts to make a const array of int, instead of the array of const int
one would get through a combined declaration.  In fact, the result is the
same, because there is a clause in ANSI C stating specifically that the 
const "falls through" in this case, affecting the inner type rather than
the array as a whole.
-- 
"Maybe we should tell the truth?"      | Henry Spencer at U of Toronto Zoology
"Surely we aren't that desperate yet." |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list