Shao Miller
5/16/2011 6:21:00 PM
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?