Date: Fri, 15 Jan 2021 19:11:47 +0100 From: Walter von Entferndt <walter.von.entferndt@posteo.net> To: Mark Millard <marklmi@yahoo.com> Cc: freebsd-hackers@freebsd.org Subject: Re: Implicit assumptions (was: Re: Some fun with -O2) Message-ID: <2310709.D6tDg3Ca2R@t450s.local.lan> In-Reply-To: <8D35ADAE-8904-4400-9DEB-7B274189BC30@yahoo.com> References: <mailman.29.1610625600.45116.freebsd-hackers@freebsd.org> <4842729.YNO7O01DYZ@t450s.local.lan> <8D35ADAE-8904-4400-9DEB-7B274189BC30@yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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. > No, CHAR_BIT is the #bits in a *char*, which is the (standard) datatype for the binary representation of a character/letter/symbol in written human language, and for small integers. The name also suggests that, as well as the comment in the header file. That does not necessarily equal a "byte", which (by commonly accepted knowledge) is the smallest addressable entity in a 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 what a "byte" is, although that term is mentioned many times in reference manuals (implicit assumption). So /theoretically/ CHAR_BIT and NBBY can differ. In fact, many library funtions operating on characters/letters take an *int* instead of a *char* for performance reasons. From https://code-reference.com/c/stdlib.h/sizeof: "the *sizeof* operator returns the number of bytes to be reserved for a variable or a data type". Of course, for practical reasons, we can safely assume that a *char* will take one byte in storage space for the foreseeable future, since the consequences of changing that would be disastrous. -- =|o) "Stell' Dir vor es geht und keiner kriegt's hin." (Wolfgang Neuss)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2310709.D6tDg3Ca2R>