Address of an array = address of its 1st element: undecidable question ?
- From: candide <toto@xxxxxxx>
- Date: Fri, 23 May 2008 02:18:47 +0200
Hi,
I try to find out what exactly means "an array and its address are the same" or "have the same value".
Everybody seems to agree that they doesn't share the same type, of course.
For enlighting the discussion, here some more or less contradictory quotes from clc and comp.std.c regarding this question :
-------------------------------- 8< -------------------------------------------
On 29 juin 2004, 06:06, lawrence.jo...@xxxxxxxxxx wrote:
> I'm not aware of any definition (or even description) of the C language
> that said that taking theaddressof anarraywas equivalent to taking
> theaddressof the first member of thearray. Certainly there were
> compilers that worked that way, but there were also many compilers that
> considered it an error and didn't allow it at all.
>
-------------------------------------------------------------------------------
On 31 déc 1996, 10:00, f...@xxxxxxxxxxxxxxxxxxx (Lawrence Kirby) wrote:
> >(...) The address of an array IS the address of
> >it's first element.
>
> The standard doesn't say so explicitly although a conforming implementation
> doesn't really have much choice in the matter. (void *)&s and (void *)&s[0]
> pretty much have to generate thesameaddress or else standard library
> functions like fread() would have problems.
-------------------------------------------------------------------------------
On 7 mai 1999, 09:00, Dennis Ritchie <d...@xxxxxxxxxxxxx> wrote:
> Paul Seale wrote:
> > OK, but what IS the address of an array? If we consider that in most
> > contexts an array name "a" is converted to &a[0], then the closest thing I
> > can imagine that would be anarray addressis the address of a cell that
> > holds &a[0]. Seems like that is just creating an unnecessary level of
> > indirection. I'd be interested in an example where this would be useful.
>
> In the usual implementation the bit value of &a[0] and &a will be the
> same,
> but the type is different (ptr to int, ptr to array of int).
> If you add 1 to them you will get different answers.
-------------------------------------------------------------------------------
On 25 fév 1996, 10:00, c2a...@xxxxxxxxxxxxxxx (Kazimir Kylheku) wrote:
> Don't be fooled by the fact that the above works. It just so happens that
> myarray and &myarray are both expressions that yield the same pointer. But the
> two pointers have a different type.
-------------------------------------------------------------------------------
On 19 sep 2006, 21:51, Keith Thompson <ks...@xxxxxxx> wrote:
[...]
> &array is a perfectly legitimate expression; it yields the address of
> the array, which is distict from the address of itsfirstelement.
> They have the "same value" in some sense, but they're of different
> types.
-------------------------------------------------------------------------------
On 11 fév 2008, 19:47, lawrence.jo...@xxxxxxxxxxx wrote:
> [...] The address of an array is the same as
> the address of its first element just as the address of a struct is the
> same as the address of its first member (the addresses are the same but
> the types are different)
-------------------------------------------------------------------------------
On 7 mai 1999, 09:00, Larry Jones <larry.jo...@xxxxxxxx> wrote:
> Paul Seale wrote:
>
> > OK, but what IS theaddressof anarray?
>
> What's theaddressof a struct? Theaddressof a struct is "the same
> as" theaddressof its first member, but they have different types.
> Likewise, theaddressof anarrayis "the same as" theaddressof its
> first element, but they have different types. (By "the same as", I
> mean that they compare equal if you convert them both to (void *)).
--------------------------------- >8 ---------------------------------------------
So what ? Is the question undecidable ?
.
- Follow-Ups:
- Re: Address of an array = address of its 1st element: undecidable question ?
- From: Szabolcs Borsanyi
- Re: Address of an array = address of its 1st element: undecidable question ?
- From: Ben Bacarisse
- Re: Address of an array = address of its 1st element: undecidable question ?
- From: Richard Heathfield
- Re: Address of an array = address of its 1st element: undecidable question ?
- Prev by Date: Re: variadic macros
- Next by Date: Re: Address of an array = address of its 1st element: undecidable question ?
- Previous by thread: send me pictures of nude little girls ...
- Next by thread: Re: Address of an array = address of its 1st element: undecidable question ?
- Index(es):
Relevant Pages
|