top | item 12526313 (no title) jibsen | 9 years ago It's worth noting that ssize_t is a POSIX type, and is only guaranteed to have the range [-1, SSIZE_MAX] (basically a size type with one error value) [1]. If you need negative sizes, then ptrdiff_t is perhaps better.[1]: http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/... discuss order hn newest vardump|9 years ago Thanks for the correction!> only guaranteed to have the range [-1, SSIZE_MAX]Oh, that's a weird type. I wonder if any compiler implementation encodes it with -1 bias, so that all bits 0 means "-1".It could cause a disaster if/when ssize_t is encoded as anything else but standard twos complement signed number... colejohnson66|9 years ago I'd assume it's just an unsigned number with 0xFF... representing -1. So counting would go (assuming 8 bits) 0xFC SSIZE_MAX - 2 0xFD SSIZE_MAX - 1 0xFE SIZE_MAX 0xFF -1 That makes more sense to me than a bias that the compiler would have to know about.
vardump|9 years ago Thanks for the correction!> only guaranteed to have the range [-1, SSIZE_MAX]Oh, that's a weird type. I wonder if any compiler implementation encodes it with -1 bias, so that all bits 0 means "-1".It could cause a disaster if/when ssize_t is encoded as anything else but standard twos complement signed number... colejohnson66|9 years ago I'd assume it's just an unsigned number with 0xFF... representing -1. So counting would go (assuming 8 bits) 0xFC SSIZE_MAX - 2 0xFD SSIZE_MAX - 1 0xFE SIZE_MAX 0xFF -1 That makes more sense to me than a bias that the compiler would have to know about.
colejohnson66|9 years ago I'd assume it's just an unsigned number with 0xFF... representing -1. So counting would go (assuming 8 bits) 0xFC SSIZE_MAX - 2 0xFD SSIZE_MAX - 1 0xFE SIZE_MAX 0xFF -1 That makes more sense to me than a bias that the compiler would have to know about.
vardump|9 years ago
> only guaranteed to have the range [-1, SSIZE_MAX]
Oh, that's a weird type. I wonder if any compiler implementation encodes it with -1 bias, so that all bits 0 means "-1".
It could cause a disaster if/when ssize_t is encoded as anything else but standard twos complement signed number...
colejohnson66|9 years ago