Re: !!, what is it?



On Mon, 12 Sep 2005 09:36:01 +0200,
Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx> wrote:
>
> As an aside:
> I recall seeing some platform specific headers which went for the
> all-bits-one representation of "true" -- but the C implementations
> gave 1 for !!TRUE as well...
>
>
int is_it_seven(int x)
{
return x==7;
}

if(is_it_seven(7) == TRUE)
printf("7 is seven\n");
else
printf("7 is not seven\n");

While I would never write the explicit test for TRUE [1], I would be
horrified at any header that defined TRUE such that this code didn't
behave as expected.

[1] Other peoples coding standards excepted.

>> One other explanation for this misunderstanding is that you may have been using
>> 1 bit bitfields: it is implementation defined whether these have values 0 and 1
>> or 0 and -1. As far as I recall, C99 did not change that.
>
> Naive question after having a look at C99, 6.7.2.1:
> Does this ambiguity only hold for "int" bitfields or also for
> "signed int" bitfields?
>
If you are using sign-magnitude or ones complement encoding then the
possible values of a signed int bitfield will be +0 and -0 or 0 and a
trap representation.

(I hope there isn't something somewhere that says that bitfields must be
twos complement. I can't see it but I'm sure if there is someone here
will be along quickly to correct me. ;-) )

Tim.

--
God said, "div D = rho, div B = 0, curl E = - @B/@t, curl H = J + @D/@t,"
and there was light.

http://tjw.hn.org/ http://www.locofungus.btinternet.co.uk/
.



Relevant Pages

  • Re: First C++ Project
    ... Neither of these two headers are part of standard C++. ... int main ... > draw line; ... it declares. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: C- Syntax to allocate Global variables to consecutive memory locations
    ... Not in standard C. ... Most compilers allow this, and don't even give a warning in their strictest ... Bitfields are generally fine too (except for enum bitfields - ... Standard C will, I believe, allocate a whole int for the bitfield, while some compilers allow bitfield types to be smaller than an int, and allocate only as much space as is needed for that type ...
    (comp.arch.embedded)
  • Re: Some Advice.
    ... int main{ ... you should use identifiers that are "self-documenting". ... you should provide inclusion guards for headers. ... function definitions into separate source files. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to calculate number of files on a disk
    ... But I'd like to also get the number of files on a disk as well. ... case I'm getting close to maxfiles, or incase the number of files ... int main { ... allocate that many headers for new files. ...
    (comp.os.vms)
  • Re: Some Advice.
    ... > int main{ ... Yes I am learning that and and implementing as I go along. ... you should provide inclusion guards for headers. ... > function definitions into separate source files. ...
    (alt.comp.lang.learn.c-cpp)