Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #4093

Re: boolean usage

From Shao Miller <sha0.miller@gmail.com>
Newsgroups comp.lang.c
Subject Re: boolean usage
Date 2011-05-16 14:21 -0400
Organization A noiseless patient Spider
Message-ID <iqrpus$o7u$1@dont-email.me> (permalink)
References <af88065a-4832-41cc-a1cd-0ea761fb8d16@glegroupsg2000goo.googlegroups.com>

Show all headers | View raw


On 5/16/2011 13:53, Joel C. Salomon wrote:
> On Monday, May 16, 2011 11:09:39 AM UTC-4, Keith Thompson wrote:
>> Datesfat Chicks<datesfa...@gmail.com>  writes:
>> [...]
>>> I typically use _Bool_ or _Boolean_ (forget what the right keyword
>>> is).  Anyway, that does a few neat things in the development tools:
>>>
>>> a)It causes the linker to manage RAM at the bit level (rather than the
>>> byte level).  So you can link a bunch of modules together each with
>>> _Bool_'s, and variables from different modules are actually often in
>>> the same byte.  No RAM wasted!  The tools pack the bits.
>> [...]
>>
>> Either your tools are generating C code that emulates 1-bit objects
>> using either bit fields or bitwise operations, or your C compiler
>> is non-conforming.  In standard C, if you apply sizeof to an object,
>> type, or expression of any type, the result is at least 1 byte,
>> which is at least 8 bits.  (sizeof can't be applied to bit fields.)
>
> A _Bool object whose address is never taken doesn't *actually* need to take up a full byte of memory; so long as you don't notice it, this is a conforming optimization.
>
> Digression:  I've been wondering whether it's possible for a compiler for a bit-addressable machine to get away with tightly-packing _Bools and still somehow get away with lying that sizeof(_Bool)==1.  The only way I can think to detect this would be something like
>
>    bool bits[16] = {0,0,0,0, 0,0,0,0, 1,1,1,1, 1,1,1,1};
>    bool bp = bits;
>    char *cp = (char *)bits;
>    assert((void *)bp == (void *)cp);
>
> -- but is that even mandated?

Is there a typographical error on the second line?  I think 'bits' would 
turn into a 'bool *' pointing at the first element, which would mean 
'bits' wouldn't be == NULL, which would make 'bp' true, wouldn't it?

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: boolean usage "Joel C. Salomon" <joelcsalomon@gmail.com> - 2011-05-16 10:53 -0700
  Re: boolean usage Shao Miller <sha0.miller@gmail.com> - 2011-05-16 14:21 -0400
  Re: boolean usage Seebs <usenet-nospam@seebs.net> - 2011-05-16 19:10 +0000

csiph-web