Do C++ signed types have modulo semantics?
Mark Mitchell
mark@codesourcery.com
Tue Jun 28 03:06:00 GMT 2005
Michael Veksler wrote:
>> Most programmers "know" that arithmetic is modulo wordsize. And those few
>>who know the right answer (only unsigned arithmetic is modulo) will
>>from time to time slip up and omit the "unsigned" keyword in their
>>declarations.
I agree.
Although the standard clearly makes signed overflow undefined, I think
it would be better if GCC defined it to be modulo arithmetic. The
degree to which that would result in inferior code seems likely to be
somewhat small, and the amount of user confusion we would eliminate, and
the number of programs that would not break with GCC, even though they
work with other compilers, seems likely to be high.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
More information about the Gcc
mailing list