Re: storage for temporaries
- From: "Old Wolf" <oldwolf@xxxxxxxxxxxxxx>
- Date: 24 Jul 2005 18:50:37 -0700
Netocrat wrote:
>Old Wolf wrote:
>> Netocrat wrote:
>>>
>>> In the original example, if sfunc().a is legal
>>> (where "a" is an array), then "a" decays to a pointer
>>
>> OK so far...
>>
>>> and therefore the storage
>>> location of the struct returned by sfunc() can be identified.
>>
>> How would you identify it? Recall Lawrence Kirby's quote:
>>
>> "... If an attempt is made to modify the result of a function
>> call or to access it after the next sequence point, the behavior
>> is undefined."
>
> Substitute "must exist" for "can be identified" then. i.e. the pointer
> value must exist, regardless of whether we can identify what it is.
>
>> So you can't printf this pointer.
>
> Agreed.
>
>> You can't do a less-than or greater-than on it either (since
>> that requires two pointers to the same object, and here we
>> allegedly have no pointers to ojbects!).
>
> Why can't you compare against an arbitrary object?
Because of 6.5.8#5 ("Relational operators") which is too large
to quote, but says informally that a relational comparison of
two pointers is undefined behaviour unless they point to the
same object (or one-past-the-end etc.)
>
> struct s { int a[1]; } s;
> struct s sfunc();
>
> if (s.a > sfunc().a)
A good example of this UB.
As for a rationale, I suppose it is unclear how to compare
pointers on a system that doesn't have a flat memory model.
They could have at least made it unspecified behaviour though.
> The comparison could be changed to any other operator including ==,
> although it is debatable whether that would be allowed to compare true.
The rules for == are different, in that you can compare
pointers to different objects. However I think that this
pointer we are discussing, would not be allowed to compare
equal to anything. I suppose that it could be the same
memory location as the actual object in the function that
has just returned, but there is no way that legal code can
verify this (barring human introspection).
.
- References:
- storage for temporaries
- From: S.Tobias
- Re: storage for temporaries
- From: Lawrence Kirby
- Re: storage for temporaries
- From: Netocrat
- Re: storage for temporaries
- From: S.Tobias
- Re: storage for temporaries
- From: lawrence . jones
- Re: storage for temporaries
- From: Netocrat
- Re: storage for temporaries
- From: pete
- Re: storage for temporaries
- From: Netocrat
- Re: storage for temporaries
- From: Joe Wright
- Re: storage for temporaries
- From: Netocrat
- Re: storage for temporaries
- From: Old Wolf
- Re: storage for temporaries
- From: Netocrat
- storage for temporaries
- Prev by Date: Re: Should function argument be changed in function body?
- Next by Date: Re: What is wrong?
- Previous by thread: Re: storage for temporaries
- Next by thread: Re: storage for temporaries
- Index(es):
Relevant Pages
|