PCC, lint bug

Wayne Throop throopw at rtp47.UUCP
Tue Sep 10 09:58:59 AEST 1985


> I'm disgusted at the number of 'wizards' who are confused.
> 'x' should best be though of as a pointer to array of two ints.
> int   y[2][2][2]; /* y should best be thought of as a pointer to
>                       two dimentional array of ints ([2][2]) */
> int   yp[][2][2] = y; /* is a proper pointer */
>                       Jeff Anton ucbvax!anton anton at BERKELEY.EDU

Now wait a minuite.  As near as I can tell from this fragment, Jeff is
as confused as any other wizard.  Since an initializer is used in the
declaration

        int yp[][2][2] = y;

yp is clearly *not* a formal.  And this being the case, *yp* *is* *not*
(I repeat *not*) a pointer.  I assume what is meant to happen for the
two above declarations is

        int y[2][2][2];
        int (*yp)[2][2] = y;

The abomination Jeff gave above declares yp to be an array of 1
array of 2 array of 2 integers, and (if the compiler doesn't choke)
initializes yp[0][0][0] to be the expression (int)y.  Yuck.

I tried this C file on SysV lint:

    int x1[2][2];
    int x2[][2] = x1;  /* I hope lint complains here */

    int (*x3)[2] = x1; /* I hope lint doesn't complain here */

And lint quite properly complained, saying:

    warning: illegal combination of pointer and integer:
        (2)  operator =

It is interesting that pointer/array equivalence causes such problems,
when it it really so simple.   The *only* (I repeat *only*) place where
a declarator like "int x[]" declares x to be a pointer is in *formal*
declarations.  In static, external, or automatic declarations, *x* *is*
*an* *array* (of compiler or loader determined size).  And even in
formal declarations, x "should be" *thought of* as an array.

--
Note that Followup-To specifies net.lang.c
--
"People who live in glass houses, shouldn't"
-- 
Wayne Throop at Data General, RTP, NC
<the-known-world>!mcnc!rti-sel!rtp47!throopw



More information about the Comp.lang.c mailing list