Re: compare a large number of variables
- From: "Mark B" <sober@xxxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 22:45:38 GMT
"Tim Rentsch" <txr@xxxxxxxxxxxxxxxxxxx> wrote in message
news:kfnwtm38cgh.fsf@xxxxxxxxxxxxxxxxxxxxxx
> "Mark B" <sober@xxxxxxxxxxxx> writes:
>
> I'm going to try to trim this down to just the relevant
> portions...
Although we disagree on what posts are pertinent to a
particular branch, I'll follow your lead and trim even more.
> unsigned char a = 3, b = 5, c = 8;
> if(a-b|b-c) ...
>
> The arguments of 'a-b' and 'b-c' are promoted (assuming
> UCHAR_MAX < INT_MAX) to 'int', and the results therefore
> are negative, with no overflow.
OK.
> Doing a bitwise OR of
> negative operands means undefined behavior; 6.5 p4.
If so, I'm missing something and would appreciate a point in the
right direction. As you know, I'm using the draft... is this what
you are in fact referring to? (if not please post appropriate text)
6.5 Expressions
...
[#4] Some operators (the unary operator ~, and the binary
operators <<, >>, &, ^, and |, collectively described as
bitwise operators) are required to have operands that have
integer type. These operators return values that depend on
the internal representations of integers, and have
implementation-defined and undefined aspects for signed
types.
The 'undefined aspects' are later identified (when applicable) in the
appropriate sections which define the operators individually.
For example, the section describing bitwise shift operators explicitly
states the specific circumstances in which using signed integer types
results in either undefined behavior, or implementation defined behavior.
(both are possible)
I don't see anything in the section which describes the inclusive OR
(6.5.12 in the draft) which cautions against using a negative operand.
The only requirement seems to be that each of the operands have
an integer type. What am I missing (or misinterpreting?)
Respectfully,
Mark
.
- References:
- compare a large number of variables
- From: Einar
- Re: compare a large number of variables
- From: Eric Sosman
- Re: compare a large number of variables
- From: Einar
- Re: compare a large number of variables
- From: Netocrat
- Re: compare a large number of variables
- From: Michael Wojcik
- Re: compare a large number of variables
- From: Netocrat
- Re: compare a large number of variables
- From: Mark
- Re: compare a large number of variables
- From: Netocrat
- Re: compare a large number of variables
- From: Mark
- Re: compare a large number of variables
- From: Mark
- Re: compare a large number of variables
- From: Netocrat
- Re: compare a large number of variables
- From: Mark
- Re: compare a large number of variables
- From: Tim Rentsch
- Re: compare a large number of variables
- From: Mark
- Re: compare a large number of variables
- From: Tim Rentsch
- Re: compare a large number of variables
- From: Mark
- Re: compare a large number of variables
- From: Tim Rentsch
- Re: compare a large number of variables
- From: Mark B
- Re: compare a large number of variables
- From: Tim Rentsch
- compare a large number of variables
- Prev by Date: Re: Why C/C++ errors are SO obscure/devious??
- Next by Date: Re: while (1) vs. for ( ;; )
- Previous by thread: Re: compare a large number of variables
- Next by thread: Re: compare a large number of variables
- Index(es):
Relevant Pages
|