Sujet : Re: do { quit; } else { }
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 14. Apr 2025, 14:00:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vtj0sr$19625$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
User-Agent : Mozilla Thunderbird
On 4/14/25 00:43, Janis Papanagnou wrote:
...
Honestly, this is an old, known argument that I could never fully
understand. 'char' for characters, 'int' as a register sized entity,
'short' and 'long' as, say, additions. So far so good. "For a wide
variety of platforms" you cannot just use 'int' and hope that works
on 8, 16, or 32 bit processors the same way. Switching to 'long' or
'short' also doesn't provide any portability property since you've
no guarantee whether the necessary ranges can be represented with
them.
Huh? There's guarantees for every one of those types.
Obviously, when interfacing with other software, I need to use the types
used in that interface. and that is the only context in which I would
use one of the exact-sized types. Whenever I'm free to choose the type
of an integer variable, I normally prefer the fast size-named types,
unless storage space is an issue, in which case I use the least
size-named types. The guarantees associated with the older types make
them roughly equivalent to the following size-named types:
[un]signed char [u]int_least8_t
[unsigned]short [u]int_least16_t
[unsigned]int [u]int_fast16_t
[unsigned]long [u]int_least32_t
[unsigned]long long [u]int_least64_t
Even before the size-named types came out, I always programmed with
those types as if they were the corresponding size-named types listed
above. Those types weren't ideal - too few of them can be described as
corresponding to one of the fast size-named types. However, they were
portable if used with due consideration of what guarantees went with
each type.