Tim Rentsch
7/4/2011 1:05:00 AM
Eric Sosman <esosman@ieee-dot-org.invalid> writes:
> On 7/3/2011 11:27 AM, Eric Sosman wrote:
>> On 7/3/2011 9:00 AM, Hill Pang wrote:
>>> For this satement:
>>> ptr[func()]=1234;
>>>
>>> if ptr is a global pointer, it would be changed by function func().
>>> My question is:
>>> for now, what's the value of ptr? the changed value or the un-changed
>>> value?
>>
>> Unspecified.
>>
>> But not "undefined," as far as I can see. The sub-expression
>> `ptr' can be evaluated before or after `func()', but not "during"
>> it. [...]
>
> "Upon further review," as they say in American football, I'll
> retract "unspecified" and vote for "undefined" after all. Although
> `ptr' cannot be evaluated "during" func(), its evaluation could
> "straddle" that of func(), part before and part after. For example,
> consider a system where pointers are two or more "atoms" long, and
> must be loaded with two or more separate operations. A possible
> translation of your code could be "Fetch some of ptr, call func(),
> fetch the rest of ptr, combine the pieces of ptr and the value from
> func() to determine where to store 1234." Changing `ptr' in the
> middle of this sequence could have unpleasant results.
Your first impression was right. The current Standard
doesn't say this clearly (the new text in C1X does),
but not too long after C90 the difference between
function calls and other kinds of sequence points
was brought out in DR 087.