Help me cast this!: Ultrix 2.x bug

SuperUser root at mfci.UUCP
Tue May 10 11:54:24 AEST 1988


Expires:

Followup-To:

Distribution:


In article <11371 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>In article <386 at m3.mfci.UUCP> root at mfci.UUCP (SuperUser) writes:
>-... "type (*)[...]" and "type **" are clearly incompatible types....
>-However, pcc compilers [without Guy Harris's fix, or equivalent]
>-don't give a warning, and I was once told that Dennis Ritchie considers
>-it to be perfectly legal C.
>
>Told by whom?

By Bjarne Stroustrup, whom I assume simply asked him.  This was the
result of a mail conversation I was having with him several years ago
over what &a should mean when a is an array.  Of course, &a is not
legal K&R C, but Bjarne thought it should be treated just like a,
i.e., that &a should yield a pointer to the first element of a.  I
argued that this was inconsistent and illogical, that if &a were legal
then it should obviously yield a pointer to a itself, not merely its
first element.  That is to say, it should have the same value as the
other form, but a different type.  Here is the example I used, which
I maintained was perfectly reasonable:

    int a[5][7];
    int (*p)[5][7];

    p = &a;

    (*p)[2][4] = 123;

This can still be accomplished in K&R C, but it is necessary to write the
assignment to p as:

    p = (int (*)[5][7]) a;

My point was that if a has type TYPE [...], then &a should have type
TYPE (*)[...] and should be equivalent to ((TYPE (*)[...]) a), so
that *&a has type TYPE [...], rather than type TYPE as he would have
had it.

Anyway, in a postscript to a reply to one of my many messages on the
subject, he wrote the following.

    PS Dennis claims that this is C:
    main()
    {
            int a[5][7] ;
            int (*p)[5][7];
            p = (int***) a;                         /* no & */
            printf("a %d p %d *p %d\n",a,p,*p);     /* a == p == *p !!! */
            (*p)[2][4] = 123 ;
            printf("%d\n",a[2][4]);                 /* 123 */
    }
    It works! Amazing!



More information about the Comp.lang.c mailing list