M
Mark
Hello,
#define ATTACH 1
#define DETACH 2
#define DIRECTION_INGRESS 1 /* Incoming */
#define DIRECTION_EGRESS 2 /* Outgoing */
if ((action != ATTACH) || (action != DETACH))
puts("invalid action");
if ((dir != DIRECTION_INGRESS) || (dir != DIRECTION_EGRESS))
puts("invalid direction");
I appears that condition within if() is verified for being TRUE or FALSE,
and it is sufficient to have just one operand of || operator to return TRUE
in order for the whole expression yield TRUE result.
For example, if action = 1, then (action != ATTACH) becomes FALSE, then
(action != DETACH) is evaluated and it will return TRUE, thus making the
statement within if() TRUE. And this is wrong behavior, given that I need to
have actoni be either 1 or 2.
To make it right, || must be replaced with &&.
Is my reasoing above correct and valid?
Thanks.
Mark.
#define ATTACH 1
#define DETACH 2
#define DIRECTION_INGRESS 1 /* Incoming */
#define DIRECTION_EGRESS 2 /* Outgoing */
if ((action != ATTACH) || (action != DETACH))
puts("invalid action");
if ((dir != DIRECTION_INGRESS) || (dir != DIRECTION_EGRESS))
puts("invalid direction");
I appears that condition within if() is verified for being TRUE or FALSE,
and it is sufficient to have just one operand of || operator to return TRUE
in order for the whole expression yield TRUE result.
For example, if action = 1, then (action != ATTACH) becomes FALSE, then
(action != DETACH) is evaluated and it will return TRUE, thus making the
statement within if() TRUE. And this is wrong behavior, given that I need to
have actoni be either 1 or 2.
To make it right, || must be replaced with &&.
Is my reasoing above correct and valid?
Thanks.
Mark.