warning: operation on 'zero' may be undefined
Paul Brook
paul@codesourcery.com
Fri Oct 1 03:12:00 GMT 2004
On Friday 01 October 2004 03:57, Mathieu Malaterre wrote:
> Hello,
>
> I am trying gcc4, and turning -Wall reveal a strange warning:
>
> int main()
> {
> int zero = 125;
> zero = (++zero)%3;
> }
>
> g++ -Wall foo.cxx
>
> foo.cxx: In function `int main()':
> foo.cxx:4: warning: operation on 'zero' may be undefined
>
> What does this mean ?
You incrementing and assigning to the same variable in one statement, which
invokes undefined behaviour.
The code you wrote can be interpreted as
zero = zero%3;
or
zero = (zero % 3) + 1
or possibly even something entirely different.
Paul
More information about the Gcc
mailing list