3 ms·
>Actually, since C99, sizeof char is defined to be 1 (byte). The number of bits in a byte is implementation-defined. (edit: i misread, it's always 1) To be ped
by gens 10y ago
>Actually, since C99, sizeof char is defined to be 1 (byte). The number of bits in a byte is implementation-defined.
(edit: i misread, it's always 1) To be pedantic, a size of char is defined by CHAR_BIT in limits.h. As well as all of the min and max values and lengths in bits for integers.
To add to the discussion, many high level languages don't have a hard min and max values (haskell, that is popular in these woods, i see has minBound/maxBound).
From the "So you think you know C?" test i answered... probably correct for the "standard" x86 implementation, while knowing that they are implementation specific (for 4 i'm not sure). The authors "Don't know" is his own, i would have answered the questions as "It depends", but that was not offered.
In the end i agree with the general notion here, that this is ugly C.
PS Integer wrapping is undefined as well, so "good" C code should work around it. (i miss this from assembly)
- sharkbot 10y ago> To be pedantic, a size of char is defined by CHAR_BIT in limits.h. As well as all of the min and max values and lengths in bits for integers. To be even more pedantic: it's the number of bits in a char that is defined by CHAR_BIT. However, sizeof returns the number of chars needed to store a type, where sizeof(char) is defined to be 1.
- gens 10y agoYes, was just about to correct myself, sizeof(char) is always 1. Nevermind me.
- rcfox 10y ago> PS Integer wrapping is undefined as well, so "good" C code should work around it. Signed integer overflow is undefined. Unsigned integer overflow is defined.