9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Digby Tarvin <digbyt@acm.org>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] thread
Date: Fri,  6 Jul 2001 17:54:34 +0100	[thread overview]
Message-ID: <200107061654.RAA07880@cthulhu.dircon.co.uk> (raw)
In-Reply-To: <20010706055512.42D78199D7@mail.cse.psu.edu> from "dmr@plan9.bell-labs.com" at "Jul 6, 2001 01:55:09 am"

Hi,

That is a fascinating little subtlety which I hadn't appreciated
before.

I was aware that the array type was special in that the application of
the '&' operator to it resulted in a change of type but not of value.

But if I understand correctly, there is a converse situation with
the type '(*)[n]' (ie address of an array) where the application
of the unary '*' operator also produces a change of type but not value.

Or said another way, the address of an array of ints is a different type
to an array of ints, but for any given array the two values are identical:

main()
{
        int     a[1];
        int     (*la)[1];

        a[0] = 10;
        la = &a;
        printf("  a = %x\n", a);	/* array of ints */
        printf(" &a = %x\n", &a);	/* address of array of ints */
        printf(" la = %x\n", la);	/* address of array of ints */
        printf("*la = %x\n", *la);	/* array of ints */
}

Which produces (gcc on BSD - sorry, Plan9 is not at hand)
	  a = efbfd91c
	 &a = efbfd91c
	 la = efbfd91c
	*la = efbfd91c

Subtle, but at least it is symmetric.

Regards,
DigbyT

dmr@plan9.bell-labs.com:
> So far as I can determine, the Plan 9 C compiler is
> conformant here.
>
> If you have, say, an
>
> 	int A[10];
>
> then just A is the address of A and has type int *.
> &A is a pointer to this array of 10 integers; it will
> have the same value, as a pointer, but a different type:
>
>  int (*)[10]
>
	[snip]
>
> 	Dennis
--
Digby R. S. Tarvin                                              digbyt@acm.org
http://www.cthulhu.dircon.co.uk


  reply	other threads:[~2001-07-06 16:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-06  5:55 dmr
2001-07-06 16:54 ` Digby Tarvin [this message]
2001-07-09  8:33   ` Douglas A. Gwyn
2001-07-09 11:46     ` Digby Tarvin
2001-07-09 17:03       ` Dan Cross
2001-07-09 11:49     ` Boyd Roberts
  -- strict thread matches above, loose matches on Subject: below --
2001-07-06  4:15 arisawa
2001-07-06 14:41 ` Dan Cross
2001-07-06 18:24   ` Boyd Roberts
2001-07-06  1:02 rob pike
2001-07-06  0:50 arisawa
2001-07-06  2:05 ` Dan Cross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200107061654.RAA07880@cthulhu.dircon.co.uk \
    --to=digbyt@acm.org \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).