4 ms·
"The problem isn't big-endian, its just platforms where sizeof(size_t) != sizeof(int)." To be honest, my memory is failing me, so I would appreciate it if some
by dllthomas 12y ago
"The problem isn't big-endian, its just platforms where sizeof(size_t) != sizeof(int)."
To be honest, my memory is failing me, so I would appreciate it if someone with a fresher understanding of the standards or BE compiler behavior would clarify.
Does a cast from (pointer to int32_t) to (pointer to int64_t) change the memory location referred to? My assumption would be not. If it does not, then there is a problem with this code on big-endian systems that does not exist on little-endian systems:
On a little-endian system, you are only reading/writing the low bits of the lengths. If anything won't fit in an int, that can be a problem. It seems plausible that other things (buffer sizes?) guarantee that can never occur, though it would still be better code not to rely on it.
On a big-endian system, you are only reading/writing the high bits of the lengths as if they were the low bits. That will almost always be wrong.