Do C++ signed types have modulo semantics?

Mark Mitchell mark@codesourcery.com
Tue Jun 28 17:02:00 GMT 2005


Joe Buck wrote:

> I don't think we should give the user any such promise, and if we do
> give such a promise, we will never catch icc.  The main problem is that
> we will no longer be able to optimize many loops.

It's entirely possible that I was naive in assuming that this wouldn't 
have a big optimization impact.  Reiterating my response to Daniel, if 
it is in fact the case that this is a major loss for optimization, then 
I would have to retract my claim.

> Here's a simple example.
> 
> int blah(int);
> 
> int func(int a, int b) {
>     if (b >= 0) {
> 	int c = a + b;
> 	int count = 0;
> 	for (int i = a; i <= c; i++)
> 	    count++;
> 	blah(count);
>     }
> }

Yes, I understand.

I just didn't imagine that these kinds of opportunities came up very 
often.  (Perhaps that's because I routinely write code that can't be 
compiled well, and so don't think about this situation.  In particular, 
I often use unsigned types when the underlying quantity really is always 
non-negative, and I'm saddened to learn that doing that would result in 
inferior code.)

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304



More information about the Gcc mailing list