Re:Did Ken, Ritchie and Brian choose wrong with NUL-terminat...
by Jtsummers on Tuesday January 16, 2018 @02:31PM
(#16161445)
A bug in an early XCom game led to character's becoming so fast that they couldn't leave the landing zone.
Stats were stored in an 8-bit field and were incremented at some (variable, depended on other factors) rate as the character leveled up. Once they hit 255 in a stat, the next time they leveled up their stat would be back to single digits.
This sort of behavior is silent in C so you have to have bounds checking yourself to make sure you don't cause underflow/overflow.
Also, be careful with enumerations. Any integer can be stored into the enumerated type and, at best, the compiler will warn you (an error if you use the right compiler flags) that you haven't cast it to the enumerated type. But nothing guarantees that it's actually in the range of the enumeration.
Stats were stored in an 8-bit field and were incremented at some (variable, depended on other factors) rate as the character leveled up. Once they hit 255 in a stat, the next time they leveled up their stat would be back to single digits.
This sort of behavior is silent in C so you have to have bounds checking yourself to make sure you don't cause underflow/overflow.
Also, be careful with enumerations. Any integer can be stored into the enumerated type and, at best, the compiler will warn you (an error if you use the right compiler flags) that you haven't cast it to the enumerated type. But nothing guarantees that it's actually in the range of the enumeration.