Sujet : Re: VMS
De : lew.pitcher (at) *nospam* digitalfreehold.ca (Lew Pitcher)
Groupes : comp.os.linux.miscDate : 01. Jul 2025, 13:44:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1040l74$2rb81$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
User-Agent : Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
On Tue, 01 Jul 2025 10:49:55 +0100, The Natural Philosopher wrote:
On 01/07/2025 04:26, c186282 wrote:
On 6/30/25 3:51 AM, Richard Kettlewell wrote:
The language spec guarantees:
char is at least 8 bits
short and int are at least 16 bits
long is at least 32 bits
long long is at least 64 bits
>
There are also some constraints on representation.
>
Server/desktop platforms usually have int=32 bits; long is a bit more
variable. It’d probably be 16 bits on a Z80 or similar where memory and
computation are in short supply.
Note that "at LEAST 8 bits", "at LEAST 16 bits" is
just BAD. Making use of modulo, roll-over, can be
very useful sometimes. If uchars are not 8 bits
exactly you get unrealized mistakes.
As I said, if its important, specify it exactly.
I am not sure that Richards' 'char is *at least* 8 bits' is correct tho...
In Kernighan & Ritchie's "The C Programming Language", the authors note that,
on the four architectures that C had been implemented on (at the time of writing),
a char occupied 8 bits on three of them. On the fourth, a char occupied 9 bits.
So, the statement that "char is *at least* 8 bits" seems true for K&R C.
In the ISO/IEC 9899:1999 draft of the ISO C standard, paragraph 5.2.4.2.1
"Sizes of integer types", the (draft) standard carries a table of required
macros and their values, with the caveat that, for each macro, "Their
implementation-defined values shall be equal or greater in magnitude
(absolute value) to those shown, with the same sign". In this table, it
lists
"number of bits for smallest object that is not a bit-field (byte)"
CHAR_BIT 8
indicating that /the mimimum/ value for CHAR_BIT (and, by implication,
the mimimum size for the number of bits in a byte) is 8, and that
implementations may use larger values for CHAR_BIT.
So, the statement that "char is *at least* 8 bits" seems true for ISO C'99.
And, similar language exists in the draft of each subsequent ISO C standard,
so the statement that "char is *at least* 8 bits" seems true for all standard
implementations of C since K&R C was documented.
-- Lew Pitcher"In Skills We Trust"