Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: CHAR_BIT is not eight Date: Wed, 02 Nov 2022 17:46:42 -0700 Organization: A noiseless patient Spider Lines: 39 Message-ID: <865yfwhnkd.fsf@linuxsc.com> References: <361b04cd-8be4-48c5-bc78-229f145eb343n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="6b01656592aeeb6f93d9ba417445f98f"; logging-data="1360051"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KsVtO0LdiVU7ZdqvC1cFlYJtLUSWekUs=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:ueX2fkhqiz40iOwJomYlqEg9IQU= sha1:AuHQapd5L8B74Iw7Y6SVTY0E12M= Xref: csiph.com comp.lang.c++:87203 Frederick Virchanza Gotham writes: > On Thursday, October 13, 2022, Juha Nieminen wrote: > >> The vast, *vast* majority of C and C++ programmers assume that 'char' >> is always 8-bit, and sometimes write code making that assumption. >> It's *extremely* rare to see any code out there that uses CHAR_BIT at >> all, but it's quite common to see code that assumes that it's 8. >> Most C and C++ programmers just assume that it's a de-facto universal >> standard, and that the actual C and C++ standards are just antiquated >> in this regard, by keeping "backwards compatibility" with some more >> exotic CPUs from the 1970's that have been completely obsolete for >> decades. >> >> I suppose there's a good reason why the language standards don't >> assume that 'char' is 8 bits, after all. > > I totally agree. I've been using C++ compilers for about 20 years > now, and yesterday was the first time I encountered CHAR_BIT != 8. > Lots of my code uses "char unsigned" and "uint8_t" interchangeably. > > > On Thursday, October 13, 2022, Mut...@... wrote: > >> A number of current Texas Instruments DSPs have 16 bit chars. >> >> Personally I always use int8_t or uint8_t if I'm writing portable >> code just to be 100% sure. > > I'm writing a 'universal header file' today that will be used in a > program on: > 1) x86_64 desktop PC > 2) microcontroller Texas Instruments F2809 (with 16-Bit bytes) > 3) microcontroller Arduino sam3x8e > > If I include "cstdint", then it doesn't have "uint8_t" on the Texas > Instruments compiler. So I'm using "uint_least8_t" in the code. Easier just to use unsigned char.