warning: operation on 'zero' may be undefined
Paul Schlie
schlie@comcast.net
Fri Oct 1 19:11:00 GMT 2004
I apologize, and won't belabor the point any further than to observe that
I believe there's nothing in the C standard which implies it's ambiguous;
to the contrary, I believe that as C clearly requires that expressions be
evaluated in their order of precedence, combined with it's requirement that
variable between sequence points be read and written no more than once
(which for all practical purposes only affects volatile semantics and
arguably code efficiency), that unless an ambiguity is introduced by the
unspecified order of evaluation of it's argument values, or expressions of
equivalent precedence, an expression's value is logically unambiguous.
Maybe I'm missing it, but no where in C do I see a license to delay the
sub-expression assignment of i in ++i [in i = ++i ;] past it's logical
rvalue evaluation as an argument to it's encompassing assignment expression,
although it's evaluation may occur prior to or following that encompassing
expression's lvalue argument evaluation, except in circumstances where that
assignment is required to be delayed and in fact logically replaced by that
encompassing assignment expression's assignment to comply with C's specified
sequence point semantics. As such if gcc is doing anything different, I
perceive it to be introducing an ambiguity not present in, and in violation
of C's semantic specification.
Just my opinion, thanks for the opportunity to express it,
-paul-
Nathan Sidwell wrote:
> Paul Schlie wrote:
>> Thanks, reviewed the faq, unfortunately question 3.3 specifies
>>
>> int i = 3 ;
>> i = i++ ;
>>
>> as having undefined behavior, erroneously referencing
>>
>> a[i] = i++ ;
>>
>>
>> as being similarly undefined, which it is; but that's because the value
>> of the index i is ambiguous as it's value is sensitive to the order
>> of lhs/rhs evaluation; which i = i++ is not.
>
> you do not understand. It is not undefined due to the ambiguity of ordering,
> it is undefined because the constraint you later quoted is not maintained.
More information about the Gcc
mailing list