Re: !!, what is it?
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Tue, 13 Sep 2005 09:12:42 +0200
Tim Woodall wrote:
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.
Sorry, without C99's _Bool and _True, this argument is bogus. Apart from the possible range of return values one could expect from is_it_seven() and the possible mismatch with, say isalnum() == TRUE or strcmp() != TRUE, there is no benefit in that. IIRC, this "TRUE" was intended for bitwise operations and conveniently fulfilled !TRUE == FALSE. However, this would not have worked on a 1s complement platform.
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. ;-) )
Sorry, I probably did not phrase it carefully enough.
This was not my question. I am well aware of s-m and 1s complement, my question more or less is whether it is possible that a signed int bitfield could be treated as if it was an unsigned int bitfield?
Here some context; see especially the footnote:
" 6.7.2.1:
4 A bit-field shall have a type that is a qualified or unqualified
version of _Bool, signed int, unsigned int, or some other implementation-defined type.
Semantics [...] 8 A member of a structure or union may have any object type other than a variably modified type.102) In addition, a member may be declared to consist of a specified number of bits (including a sign bit, if any). Such a member is called a bit-field;103) its width is preceded by a colon. 9 A bit-field is interpreted as a signed or unsigned integer type consisting of the specified number of bits.104) If the value 0 or 1 is stored into a nonzero-width bit-field of type _Bool, the value of the bit-field shall compare equal to the value stored. ____ 104) As specified in 6.7.2 above, if the actual type specifier used is int or a typedef-name defined as int, then it is implementation-defined whether the bit-field is signed or unsigned. "
Cheers Michael -- E-Mail: Mine is an /at/ gmx /dot/ de address. .
- Follow-Ups:
- Re: !!, what is it?
- From: Tim Woodall
- Re: !!, what is it?
- References:
- !!, what is it?
- From: bjk of course
- Re: !!, what is it?
- From: Mike Wahler
- Re: !!, what is it?
- From: Cafer Şimşek
- Re: !!, what is it?
- From: Flash Gordon
- Re: !!, what is it?
- From: Kenneth Brody
- Re: !!, what is it?
- From: Charlie Gordon
- Re: !!, what is it?
- From: Michael Mair
- Re: !!, what is it?
- From: Tim Woodall
- !!, what is it?
- Prev by Date: Re: Should use of goto completely avoided in programs?
- Next by Date: Re: offsetof() macro
- Previous by thread: Re: !!, what is it?
- Next by thread: Re: !!, what is it?
- Index(es):
Relevant Pages
|