Xref: utzoo comp.lang.c:13796 comp.std.c:477 Newsgroups: comp.lang.c,comp.std.c Path: utzoo!utgpu!jarvis.csri.toronto.edu!csri.toronto.edu!norvell From: norvell@csri.toronto.edu (Theodore Stevens Norvell) Subject: Re: union *func() Message-ID: <8811040120.AA03874@davenport.csri.toronto.edu> Organization: University of Toronto, CSRI References: <2205@arcturus> <14172@mimsy.UUCP> <1585@solo8.cs.vu.nl> <14201@mimsy.UUCP> <7686@boring.cwi.nl> <7689@boring.cwi.nl> Date: Thu, 3 Nov 88 20:20:43 EST In article <7689@boring.cwi.nl> guido@cwi.nl (Guido van Rossum) writes: >In article <7686@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@csri.utoronto utzoo!utcsri!norvell