Path: utzoo!mnetor!uunet!yale!mfci!root
From: root@mfci.UUCP (SuperUser)
Newsgroups: comp.lang.c
Subject: Re: Help me cast this!: Ultrix 2.x bug
Message-ID: <392@m3.mfci.UUCP>
Date: 10 May 88 01:54:24 GMT
References: <294@fedeva.UUCP> <1451@iscuva.ISCS.COM> <11344@mimsy.UUCP> <386@m3.mfci.UUCP> <11371@mimsy.UUCP>
Reply-To: karzes@mfci.UUCP (Tom Karzes)
Organization: Multiflow Computer Inc., Branford Ct. 06405
Lines: 51
Keywords: pointer to array of struct
Summary:

Expires:

Followup-To:

Distribution:


In article <11371@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>In article <386@m3.mfci.UUCP> root@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!