3 ms·
To expand further on that: POSIX only says that ssize_t needs to be able to store -1, i.e. the valid range is from -1 through 0 to some implementation defined m
by st_goliath 4y ago
To expand further on that: POSIX only says that ssize_t needs to be able to store -1, i.e. the valid range is from -1 through 0 to some implementation defined maximum. (See the link in the article)
A really cursed implementation could hack up compiler support for an asymmetric integer type that treats all-bits-set as -1 and everything else as a positive number, allowing ssize_t to hold all but the largest size_t values. While perfectly standards compliant, I guess this might break a bunch of implicit assumptions across various existing programs.
- riceart 4y agoThis isn’t particularly uncommon or without precedent. This is just treating SIZE_MAX as the sentinel value of an otherwise unsigned type. This is what is done for std::dynamic_extent in C++ for instance.
- im3w1l 4y agoThere's a really neat way to express asymmetric numbers that generalizes from both unsigned numbers and standard 2's complement signed numbers. It's easiest to explain in terms of how to interpret a particular bitpattern. As the first step, interpret the bitpattern as an unsigned int, u. If u <= T, for some threshold T, then we are done, the final value is u. If u > T, then we interpret it as the negative number u - UINT_MAX. T = UINT_MAX gives you the unsigned numbers, and T = INT_MAX gives you the two's complement. Because of modulus intense handwaving it's also easy to do addition, subtraction and multiplication using this representation.
- fanf2 4y agoThat isn’t allowed by the C standard: signed integer types have to be two’s complement, one’s complement, or sign-magnitude; they can’t be wildly asymmetrical about 0.
- deleted 4y ago[deleted]