Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news2.arglkargh.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: counting bytes Date: Mon, 20 Jul 2015 11:18:16 -0700 Organization: None to speak of Lines: 52 Message-ID: References: <87eglns3jc.fsf@kst-u.example.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="18575"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xJ+mhDgbtEPFqodMP+Wi0" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:w90Y2WxOYEne1bivHFwv8HV3f0E= sha1:6zN98uyLd01Dt1wLlWcaI4oLzlo= Xref: csiph.com comp.lang.c:66036 Tim Rentsch writes: > Keith Thompson writes: >> Tim Rentsch writes: [...] >>> It is possible to have a conforming implementation with >>> CHAR_BIT > 8 but still having a type that occupies only eight >>> bits. AFAIK there is no reason such an implementation >>> could not use that type to provide the [u]int8_t types. >> >> I'm skeptical. > > The combination of undefined behavior resulting from trap > representatons and the Standard allowing an extremely wide > range of extensions is enormously powerful. In some sense > it's an academic question since such an implementation will > in all likelihood never be produced. But I think it's > interesting to consider the possibility. Sure -- but I still don't think it's a possibility. Extensions can take advantage of undefined behavior, but your proposed extension (using padding bits and trap representations in size_t to represent fractional values) introduces undefined behavior where it doesn't currently exist. I believe it is therefore non-conforming. I believe that this program: #include #include int main(void) { #ifdef UINT8_MAX if (sizeof (uint8_t) < (size_t)1) { puts("I am confused"); } else { puts("ok"); } #else puts("ok"); #endif return 0; } is strictly conforming (subject to the usual caveats about the puts call failing) and must print "ok". -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"