3 ms·
Many if not most of the embedded/long term systems are implemented in C. If a variable is declared signed, overflowing cases may and often are "optimized" away.
by labawi 6y ago
Many if not most of the embedded/long term systems are implemented in C. If a variable is declared signed, overflowing cases may and often are "optimized" away.
IIUC, GP's foo() would likely be optimized to { return true; }, and so would similar timestamp overflow checks.
- deleted 6y ago[deleted]
- dragontamer 6y agoThe post I responded to was the opposite: about turning "signed" code (which you declare is undefined) into "unsigned" code (which you declare is fully defined). Given this thread of subargument, making the difference between 32-bit unsigned numbers is MORE DEFINED than using signed integers. ------- IE: If your code was correct with "int timestamp", it will be more correct with "unsigned int timestamp". In any case, "int" or "unsigned int" based timestamp manipulation wouldn't be like the code you suggested, but instead "int difference = x - y". In the signed integer case, "difference" is (conceptually) negative, while in the unsigned integer case, "difference" is guaranteed to have overflow. Both cases are conceptually correct with regards to the difference of timestamps.