No, the compiler is, by spec, required to do stupid things. Result of bitshift on a signed number is compiler-defined.First of all, this is C, I don't care about what the flags are or anything (the compiler takes care about that). And this code assumes overflow shouldn't happen (if it does then it's considered a bug in the game).
Second, the only behavior that matters here is the result the function returns, not what the compiler decides to do inside (though ideally the compiler should not do stupid things to achieve it!).
So whatever you're trying to emulate "correctly" has nothing to compare to.
The following function is correct:
int32_t speed_to_int(int32_t value) {
if (value + comma_offset >= 0) return (value+comma_offset) / 256;
return rand();
}For a given compiler that chooses such behavior. C language does not forbid it, compiler that generates code like above is perfectly C standard compliant.Since that is probably not what you intended, it is up to you what the supposed result will be and how it's implemented.
If log replayes across machines (as mentioned above) are important, then any behavior will do, as long as its consistent.
But there is no way to provide 1:1 correct version, since original one is undefined, the only thing one can do is compare against a specific result of a specific compiler.


Find content
Not Telling