3 ms·
Why do some people store chars to store numbers?
by bogomipz 11y ago
Why do some people store chars to store numbers?
- douche 11y agoThey need a char-sized number, and memory used to be a tightly-budgeted commodity. Reminds me of this story of a game developer who magically got their game under the limit at the 11th hour http://www.dodgycoder.net/2012/02/coding-tricks-of-game-developers.html http://www.dodgycoder.net/2012/02/coding-tricks-of-game-deve...
- Kristine1975 11y agoAlthough char should not be used to store numbers, since its signedness is implementation-defined (gcc has the switch -funsigned-chars I think to make them unsigned instead of signed). signed char/unsigned char are ok.
- dgacmu 11y agoBecause uint8_t is comparatively new. C99, IIRC, though many OSes defined their own earlier.
- pjmlp 11y agoBecause unlike other programming languages C didn't define a type called byte, so developers were forced to use char for what is byte in saner systems programming languages. With the caveat that unless you precede them with signed/unsigned modifiers, it is not portable.