A lot of people blame the compiler, but I'm pretty sure the problem mostly is the programmer.PK wrote:hi,
I have noticed similar node count changes in two more places, both unrelated to hash tables or evaluation. Again, changes appear only under my "release" configuration, which is optimized for speed. This time one of the modifications was simply moving a one-line conditional instruction into a separate function and I cannot possibly imagin what could have been wrong with that.
It looks like we ought to change the name of the thread to something like: problem with Visual C++ Express Edition.
Pedro, thanks for Your observation about badCaptures(), I messed something up because of misguided pretty-printing a couple of weeks ago. The function with a single "=" simply did not work. Still, I am not sure if this should be included in a simple, didactic program. Any opinions?
I've had problems like this too, and only once I could (slightly) blame the compiler because it didn't behave like expected ( though correct)
There are some things that help.
Use Asserts for sanity checks. ( or let your code crash on wrong input)
If you know a parameter to a function should never be <0 then you can put code like: if (param<0) param=0;
But since param should never be<0 it can bever behave the way you want. Using Assert(param>=0) ( or raise an exception) shows the problem, rather than hiding it.
Solve your warnings. The fact that the "=" and "==" could be missed means you either have the wrong warning level, or you don't read them.
Good code compiles without warnings. ( if you select a normal warninglevel that is)
Another one is : If you're not sure in wich order something is evaluated, use ().
fe if ( condA || condB) can give problems depending on the conditions A and B,
if ((condA) || (condB)) is a lot less likely to be unclear.
Tony