Date: Fri, 15 Jan 2021 10:40:50 -0800 From: Mark Millard <marklmi@yahoo.com> To: Walter von Entferndt <walter.von.entferndt@posteo.net> Cc: freebsd-hackers@freebsd.org Subject: Re: Implicit assumptions (was: Re: Some fun with -O2) Message-ID: <F90A3341-09BB-473D-8257-E581B0AED885@yahoo.com> In-Reply-To: <FA82F286-8818-45B8-81C0-CE8A85BBB366@yahoo.com> References: <mailman.29.1610625600.45116.freebsd-hackers@freebsd.org> <4842729.YNO7O01DYZ@t450s.local.lan> <8D35ADAE-8904-4400-9DEB-7B274189BC30@yahoo.com> <2310709.D6tDg3Ca2R@t450s.local.lan> <FA82F286-8818-45B8-81C0-CE8A85BBB366@yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2021-Jan-15, at 10:35, Mark Millard <marklmi at yahoo.com> wrote: > On 2021-Jan-15, at 10:11, Walter von Entferndt = <walter.von.entferndt@posteo.net> wrote: >=20 >> At Freitag, 15. Januar 2021, 08:02:49 CET Mark Millard wrote: >>> FYI: C itself has, in <limits.h> , CHAR_BIT for the number of bits = in a >>> Byte for how sizeof counts Bytes: sizeof(char), sizeof(signed = char), >>> and sizeof(unsigned char) are each always 1. >>>=20 >> No, CHAR_BIT is the #bits in a *char*, which is the (standard) = datatype for=20 >> the binary representation of a character/letter/symbol in written = human=20 >> language, and for small integers. The name also suggests that, as = well as the=20 >> comment in the header file. That does not necessarily equal a = "byte", which=20 >> (by commonly accepted knowledge) is the smallest addressable entity = in a=20 >> computer's memory. Of course, e.g. = https://code-reference.com/c/datatypes/ >> char tells a *char* occupies one byte. Sadly, AFAIK C itself does = not define=20 >> what a "byte" is, although that term is mentioned many times in = reference=20 >> manuals (implicit assumption). So /theoretically/ CHAR_BIT and NBBY = can=20 >> differ. In fact, many library funtions operating on = characters/letters take=20 >> an *int* instead of a *char* for performance reasons. =46rom = https://code-reference.com/c/stdlib.h/sizeof: "the *sizeof* operator = returns the number of=20 >> bytes to be reserved for a variable or a data type". Of course, for = practical=20 >> reasons, we can safely assume that a *char* will take one byte in = storage=20 >> space for the foreseeable future, since the consequences of changing = that=20 >> would be disastrous. >=20 > Have you read a (fairly modern) C standard or its officially > published rationle? You might want to. >=20 > =46rom the officially published C99 rationale (page labeled 11, > Terms and definitions): >=20 > QUOTE > ) All objects in C must be representable as a contiguous sequence of = bytes, > each of which is at least 8 bits wide. >=20 > ) A char whether signed or unsigned, occupies exactly one byte. >=20 > (Thus, for instance, on a machine with 36-bit words, a byte can be = defined > to consist of 9, 12, 18, or 36 bits, these numbers being all the exact > divisors of 36 which are not less than 8.) These strictures codify the > widespread presumption that any object can be treated an an array of > characters, the size of which is given by the sizeof operator with = that > object's type as its operand. > END QUOTE I should have reported that my rationale copy (.pdf) is of: QUOTE Rationale for International Standard-- Programming Languages -- C Revisision 5.10 April-2003 END QUOTE =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F90A3341-09BB-473D-8257-E581B0AED885>