Excerpt from code I recently saw:
#define EIGHT (0x08)
#define NINE (0x09)
#define TEN (0x10)
. . .
I hope I wasn't too subtle - the definition of TEN is what is ... interesting here.
Excerpt from code I recently saw:
#define EIGHT (0x08)
#define NINE (0x09)
#define TEN (0x10)
. . .
I hope I wasn't too subtle - the definition of TEN is what is ... interesting here.
Good thing they put parentheses around those literals!
edit:
Oh gosh, I didn't even realize the TEN issue... That's horrible.
edit:
Oh gosh, I didn't even realize the TEN issue... That's horrible.
That edit made my day :D - that is exactly why this is so scary.
an explanation for the more noobish of us? what's wrong with that definition? >_<;
0x10 in 16 in hex.
Could be binary coded decimal... and it makes outputting a text value easier as well ;)
Manic Miner on the ZX Spectrum didn't even store the game score or high score in a variable... it just used ASCII text on the screen (the screen area where the score was displayed was never cleared).
The algorithm only added to your score either 1 or 10 or 100 at a time IIRC. It just increased the ASCII value at the screen position by 1 and if that makes it > 9 it made the current digit 0 and added 1 to the next digit along (and looped if that was bumped to > 9 as well).
It then just copied the score to the high score location if the score was larger than the current high score (check was done with another ASCII comparison).
Could be binary coded decimal... [snip]
That sounds so convoluted it requires its own thread.
Unfortunately that wasn't the case here - this code, according to a colleague who originally fixed it - caused a fatal crash in the software.
... maybe the use of named constants is what was at fault here ...Obvious, the coder has 8 fingers on each hand