T
Tim Rentsch
Johannes Bauer said:Wow -- I really don't feel bad about tripping over this now.
It *is* indeed confusion and without a *lot* of insight into
the standard it is quite hard to tell what the expression will
evaluate to on different platforms.
In practice it isn't hard to say what the result will be, because
the "pathological" implementations with such bizarre behavior are
very rare (indeed, I conjecture that none exist), and very likely
a developer would know if his platform had such issues. Granted,
the rule for converting the signed type to the unsigned type does
need to be known, but people who use mixed-mode arithmetic should
be familiar with that for other reasons (eg, comparisons).
When C was originally standardized, there was a big debate about
how to do integer promotions (in particular, should types like
'unsigned short' promote to signed int or unsigned int?). So
here's another case for you:
unsigned short us_30 = 30;
unsigned int ui_30 = 30;
int minus_one = -1;
// now, what is the result of
if( minus_one % us_30 == minus_one % ui_30 ) ... etc ...
Does the "etc" get executed or not? You might enjoy looking
into the Standard and see what you can make of this question.