3 ms·
I guess I should be the one to provide the usual warning that C and C++ make no guarantees about the in-memory representation of the built-in types, and that th
by antipax 17y ago
I guess I should be the one to provide the usual warning that C and C++ make no guarantees about the in-memory representation of the built-in types, and that this type of code can be very dangerous.
It is, however, very cool when it works.
- jules 17y agoNo. They might not guarantee the representation, but they do guarantee that the operations (e.g. >> & |) work.
- scott_s 17y agoThere actually are guarantees, they're just a guarantee of ranges. (When bit-twiddling, you always want to use the unsigned version.) char is guaranteed to be at least 8 bits. short is guaranteed to be at least 16 bits. int is guaranteed to be at least 16 bits. long is guaranteed to be at least 32 bits. long long is guaranteed to be at least 64 bits. unsigned long is guaranteed to be the same size as a pointer.
- mahmud 17y agoyou want to use "unsigned" and "register".
- mahmud 17y agoyou want to use "unsigned" and "register".
- Locke1689 17y agoLook up C99 and stdint.h. You will be pleasantly surprised.
- antipax 17y agoConsider me educated.