union *func()

Theodore Stevens Norvell norvell at csri.toronto.edu
Fri Nov 4 11:20:43 AEST 1988


In article <7689 at boring.cwi.nl> guido at cwi.nl (Guido van Rossum) writes:
>In article <7686 at boring.cwi.nl> I wrote:
>>Chris's original posting said that "v = func().a" is legal, unless a is
>>an array.  
>
>I received a mail message stating that in fact *any* use of func().a is
>illegal when a is an array member; the reason being that this use of an
>array name requires conversion to a pointer to its first element, and of
>course Chris has adequately explained why that should be illegal.
>
>I suppose that it is thus even illegal to write something like
>"v = func().a[0]", even though that would make perfect sense (all
>Chris's examples showed cases where a's address or the address of some
>element was actually saved).  I suppose it would be possible to change
>various rules about pointers, arrays, rvalues and lvalues to fix this,
>but nobody cared.

[I presume you mean ``nobody cared to do so'', or, to put it more
positively, that the commttee cared that the indexing rules were simple
and uniform. :-)]

Yes.  func().a[0] is not legal.  The problem with it is that the proposed
standard defines array indexing in terms of addresses.  The example is
equivalent to *(func().a + 0) where func().a is the address of the first
element of the array.  But, as the array (being a member of an rvalue)
does not have an address, it does not make sense (even though it is clear
what is meant).

It is still not clear to me that func().a itself is illegal, though it
is clear that its use is limited.  Perhaps someone who knows the proposed
standard intimately would care to comment on whether, for example,
	sizeof( func().a )
is legal. Note that, contrary to the mail message Guido recieved, in ANSI C,
arrays arguments to sizeof are not coerced to pointers.  If func().a is not
legal can someone explain exactly why.


Theodore Norvell
norvell at csri.utoronto
utzoo!utcsri!norvell




More information about the Comp.std.c mailing list