
on 01.05.2010 at 21:56 Chad Nelson wrote :
i meant this: in the followng code (monty.cpp)
00033 digit_t inverse0(const integer& n) { 00034 // Using the Duss and Kalisk simplification 00035 doubledigit_t x = 2, y = 1; 00036 digit_t n0 = n._get_digit(0); 00037 for (size_t i = 2; i <= bits_per_digit; ++i, x <<= 1) 00038 if (x < ((n0 * y) & ((x << 1) - 1))) 00039 y += x; 00040 return digit_t(x - y); 00041 }
Ah, I see. POD types in the internals. :-)
not only pod types but any types
the variable 'n0' is not modified so it actually is const (and should be declared such) 'x' is not modified in this piece as well
(It's modified -- look at the end of the "for" line.)
my bad, sorry
this is a minor issue and concerns style of coding so it is arguable by definition however scott meyers, andrei alexandrescu and herb sutter recommend to make everything const unless it must be modifyed so you might want to decide to follow this recommendation ...or not
It sounds like a good practice. It would be useful to catch some typos at compile-time, where you use one variable but meant to use a different one (something I've done on occasion). And as you said, it does make code more readable, so I'll try to adopt now that I know about it.
But since the compiled code will be identical either way, for POD types, I don't think it warrants combing through the code to correct violations of it. I'll change them when I find them during refactoring.
you've got it absolutely right -- Pavel P.S. if you notice a grammar mistake or weird phrasing in my message please point it out