[Freeciv-Dev] Re: (PR#2521) general effects framework
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Mon, Mar 10, 2003 at 09:03:17PM -0800, Mike Kaufman wrote:
> If someone could please give me the low-down on | and & versus || and &&
> I'd appreciate it. I ran into a problem with the bitfields and &&: it
> evaluated to zero no matter the arguments.
Lets take a look at the standard. (I love citing standards).
------ start -----
6.5.10 Bitwise AND operator
Each of the operands shall have integer type.
The usual arithmetic conversions are performed on the operands.
The result of the binary & operator is the bitwise AND of the operands
(that is, each bit in the result is set if and only if each of the
corresponding bits in the converted operands is set).
6.5.11 Bitwise exclusive OR operator
Each of the operands shall have integer type.
The usual arithmetic conversions are performed on the operands.
The result of the ^ operator is the bitwise exclusive OR of the
operands (that is, each bit in the result is set if and only if
exactly one of the corresponding bits in the converted operands is
set).
6.5.12 Bitwise inclusive OR operator
Each of the operands shall have integer type.
The usual arithmetic conversions are performed on the operands.
The result of the | operator is the bitwise inclusive OR of the
operands (that is, each bit in the result is set if and only if at
least one of the corresponding bits in the converted operands is set).
6.5.13 Logical AND operator
Each of the operands shall have scalar type.
The && operator shall yield 1 if both of its operands compare unequal
to 0; otherwise, it yields 0. The result has type int.
Unlike the bitwise binary & operator, the && operator guarantees
left-to-right evaluation; there is a sequence point after the
evaluation of the first operand. If the first operand compares equal
to 0, the second operand is not evaluated.
6.5.14 Logical OR operator
Each of the operands shall have scalar type.
The || operator shall yield 1 if either of its operands compare
unequal to 0; otherwise, it yields 0. The result has type int.
Unlike the bitwise | operator, the || operator guarantees
left-to-right evaluation; there is a sequence point after the
evaluation of the first operand. If the first operand compares unequal
to 0, the second operand is not evaluated.
------ end -----
You should only use && and || with the bitfield. If you need to
perform bitwise AND and OR please add these as functions like
bv_check_mask.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"If at first you don't succeed... well so much for skydiving."
- [Freeciv-Dev] (PR#2521) general effects framework, Mike Kaufman, 2003/03/10
- Message not available
- [Freeciv-Dev] Re: (PR#2521) general effects framework,
Raimar Falke <=
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Mike Kaufman, 2003/03/11
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Raimar Falke, 2003/03/11
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Mike Kaufman, 2003/03/11
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Raimar Falke, 2003/03/11
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Mike Kaufman, 2003/03/11
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Raimar Falke, 2003/03/11
- [Freeciv-Dev] Re: (PR#2521) general effects framework, rwetmore@xxxxxxxxxxxx, 2003/03/11
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Raimar Falke, 2003/03/12
- [Freeciv-Dev] Re: (PR#2521) general effects framework, rwetmore@xxxxxxxxxxxx, 2003/03/12
- [Freeciv-Dev] Re: (PR#2521) general effects framework, Raimar Falke, 2003/03/13
|
|