Declaration puzzler (another old question?)

Norman Diamond diamond at csl.sony.JUNET
Thu Oct 6 11:55:54 AEST 1988


In article <30091 at oliveb.olivetti.com>, chase at orc.olivetti.com (David Chase) writes:
> I can't figure out how to declare the type of an array with (say) 10
> elements, each of which is that array type.  That is, I want the
> non-error effect of
> 
> 	typedef foo *(foo[10]);
> 
                ^#1   ^#2

The problem is that you're trying to use foo #1 to define foo #2.
At the time of using foo (#1), it hasn't been defined yet.  Except
for structure tags (and other similar tags), you cannot use an
identifier before it is declared.
 
>   "If T is any C type except void or 'function returning ...,'
>   the array type 'array of T' may be declared."

An undefined identifier is not any C type.
 
> I can succeed, however, if I wrap the array up in a structure, as in
> 
>   struct mumble {
>     struct mumble * children[10];
>   };

Yes ... structs are maybe 0th-class citizens, ahead of 1st-class.
 
> I might think that arrays were a second-class type.

You also can't do typedef bar bar; or typedef flub flub(); or
typedef plunk *plunk; so arrays don't seem to be second to most
other types.
-- 
-------------------------------------------------------------------------------
  The above opinions are my own.   |   Norman Diamond
  If they're also your opinions,   |   Sony Computer Science Laboratory, Inc.
  you're infringing my copyright.  |   diamond%csl.sony.jp at relay.cs.net



More information about the Comp.lang.c mailing list