Posted on:March 06 2008
I really want to bang my head against something when I spent an hour debugging a problem again and found it to be a simple typo. For example, I found the problem in the following code (not originally C++ but translated to C it would look like this). It simply should count the numbers of bits set in a value:
value = some value where we want to count the number of bits set in it.
testBit = 0x1;
bitsSet = 0;
for (int i=0; i<16; ++i)
if (value & testBit)
bitsSet += 1;
testBit << 1;
See the problem? Yep, it's the last line. Instead of 'testBit << 1;', it should read 'testBit = testBit << 1;'. Argh. Too bad the compiler didn't write a warning, because that line doesn't actually make sense at all, in any case.
|Link ||[url] www.example.com [/url] |
|Bold ||[b]bold text[/b] |
|Quote ||[quote]quoted text[/quote] |
|Code ||[code]source code[/code] |