How to include char arrays of pointers in structures
Chris Torek
chris at mimsy.umd.edu
Wed May 2 17:30:32 AEST 1990
In article <24003 at mimsy.umd.edu> I wrote:
>(You should get a diagnostic for this ... because the type of &a is
>(char *(*)[10]), while the type of ptr is (char *(*)[]), and the numbers
>in the brackets do not match.)
Norman Diamond has pointed out that the ANSI C standard says otherwise:
a pointer to an incomplete array type (one without a size) is compatible
with a pointer to a complete array type of any size, provided that
the types match when the size is not considered. In other words,
a pointer of type
T (*)[]
is compatible with both one of type
T (*)[10]
and
T (*)[20] ,
and a pointer of type
T (*)[3]
is compatible with one of type
T (*)[] .
This does not, however, affect my original point: there is nothing you
can do with a pointer of type (T (*)[]) that you cannot do with one of
type (T *), except confuse a human reading your code. (There *is*
something new you can do if you put a number inside the brackets. This
rule should be applied only to pointers to `sizeless' arrays.)
--
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