Annoying compiler warning

R

Richard Heathfield

James Kuyper said:
Section 6.2.6.2p1 of the C99 standard is quite clear about this; if N is
the number of value bits in an unsigned type, the corresponding maximum
is 2^N-1, which is inherently never a negative number.

ITYM "never an even number".

But of course, it is easy to show that this is wrong. If N is, say,
15.000044+ (i.e. if there are 15.000044+ value bits in the unsigned type),
then the maximum is 32768, which is an even number.
 
J

James Kuyper

Richard said:
James Kuyper said:


ITYM "never an even number".

But of course, it is easy to show that this is wrong. If N is, say,
15.000044+ (i.e. if there are 15.000044+ value bits in the unsigned type),
then the maximum is 32768, which is an even number.

I suppose you're correct; the standard never specifically requires that
there be an integer number of value bits. :)
 
E

Eric Sosman

Richard said:
James Kuyper said:


ITYM "never an even number".

But of course, it is easy to show that this is wrong. If N is, say,
15.000044+ (i.e. if there are 15.000044+ value bits in the unsigned type),
then the maximum is 32768, which is an even number.

The Standard requires a "pure binary representation," but
the representation you suggest can only be called "impure."
 
S

santosh

James said:
I suppose you're correct; the standard never specifically requires
that there be an integer number of value bits. :)

The standard never specifically requires C to be restricted to computer
programming alone. :)
 
C

Chris Dollin

Eric said:
Richard Heathfield wrote:

The Standard requires a "pure binary representation," but
the representation you suggest can only be called "impure."

Rubbish. "Bloody stupid" would be a reasonable alternative.
 
C

CBFalconer

Eric said:
.... snip ...

The Standard requires a "pure binary representation," but
the representation you suggest can only be called "impure."

Ahh, now we are getting to something of general interest.
 
W

Walter Roberson

Eric Sosman said:
The Standard requires a "pure binary representation," but
the representation you suggest can only be called "impure."

Is that the C99 Standard? Is there a corresponding C89 clause?

I've been reviewing C89 but I have not yet found in there any
requirement of binary representation, beyond that implied by the definition
of "bit" and "byte". I also have not found any requirement in C89
that the complete possible span of binary be usable as values.

If there is anything in C89 that would prevent UINT_MAX from being
2^N-2 with 2^N-1 reserved as a trap value, could someone point me
to the relevant C89 clauses?
 
B

Ben Pfaff

Is that the C99 Standard? Is there a corresponding C89 clause?

From C89 6.1.2.5 "Types": "The representations of integral types
shall defines values by use of a pure binary numeration system."
 
W

Walter Roberson

(e-mail address removed)-cnrc.gc.ca (Walter Roberson) writes:
From C89 6.1.2.5 "Types": "The representations of integral types
shall defines values by use of a pure binary numeration system."

Thanks. It appears the C89 clause is 3.1.2.5; "6.1.2.5" must be the C90
numbering.

I do see the quoted sentance in C89 now, but even with all of the
discussions there about subranges and representations, it is not
yet clear to me that in C89, UINT_MAX could not be 2^N-2 with 2^N-1
reserved. (It would require more than 16 bits for int, but that's not
difficult at all these days.)
 
J

jameskuyper

Walter Roberson wrote:
....
If there is anything in C89 that would prevent UINT_MAX from being
2^N-2 with 2^N-1 reserved as a trap value, could someone point me
to the relevant C89 clauses?

Well, the fact that the standard didn't officially acknowledge the
possibility of trap values until C99 would be a bit of a barrier to
that possibility.
 
A

Army1987

Ian Collins wrote:
[About infinite loops]
How about:

for( u = 1; u&1; u += 2 )
It's the reversed form of the Italian humorous threat "Ti prendo a
schiaffi a due a due finché non diventano dispari", "I'm giving you slaps
two by two until they become odd".
BTW, what about
#define HELL_TEMPER 1.416785e32 /* actually, Planck temperature */
#define FREEZING_TEMPER 273.15
#define HELL_FREEZES_OVER (HELL_TEMPER < FREEZING_TEMPER)

while (!HELL_FREEZES_OVER) { ... }
?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top