Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: CHAR_BIT is not eight Date: Wed, 12 Oct 2022 17:16:37 -0700 Organization: None to speak of Lines: 38 Message-ID: <877d144ly2.fsf@nosuchdomain.example.com> References: <361b04cd-8be4-48c5-bc78-229f145eb343n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="bc4abb35f1b65d9e1c62f7a5c5f65cdf"; logging-data="1696743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7dUWXgZic7y+VL6Yt+2cC" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:Uaf3jXbXpdo/XVB4d7QAGuwO44I= sha1:XQZMV92SxmmZVMDcfii+p6+ANMo= Xref: csiph.com comp.lang.c++:86897 Frederick Virchanza Gotham writes: > Since I started programming in C/C++ back in the early 2000's, I never > encountered a compiler with CHAR_BIT anything other than 8. > > Well just now in the past 15 minutes, I was trying to get the code for > the 'base58' algorithm to compile for the Texas Instruments F2809 > microcontroller using the 'cl2000' compiler. > > At first I was puzzled as to why 'sizeof(long)' was coming back as > 2. Of course my first assumption here was that 'long' was 16-Bit (even > though the Standard says that a 'long' must be at least 32-Bit). So I > figured that this compiler was just non-standard-compliant on a few > issues. > > After a little messing around, I realised that CHAR_BIT is 16. > > I looked through the compiler manual and found this paragraph: > > "By ANSI/ISO C definition, the sizeof operator yields the number of > bytes required to store an object. ANSI/ISO further stipulates that > when sizeof is applied to char, the result is 1. Since the TMS320C28x > char is 16 bits (to make it separately addressable), a byte is also 16 > bits. This yields results you may not expect; for example, size of > (int) = = 1 (not 2). TMS320C28x bytes and words are equivalent (16 > bits). To access data in increments of 8 bits, use the __byte() and > __mov_byte() intrinsics described in Section 7.6" > > So there you go: There are C++ compilers in use today in the year 2022 > with CHAR_BIT something other than 8. Apparently the TMS320C28x is a DSP (Digital Signal Processor). I've heard that it's common for CHAR_BIT to be 16 or 32 in implementations for DSPs. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */