Skip to main content
gamedev.net
🔒 Locked

(!( && !

Started by Tazel 13 replies 450+ views
Original Post
Tazel
Tazel
Do these things mean the same thing:
if(!(blah))
return(0);
  
and
if(!blah)
return(0);
 
BTW, if(blah) is checking whether or not blah is existant? [edited by - Tazel on January 28, 2003 4:46:18 PM]
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Sneftel
Sneftel
They mean the same thing. They are each checking whether the value in "blah" is equal to 0.


Don't listen to me. I've had too much coffee.

[edited by - sneftel on January 28, 2003 4:49:40 PM]
Tazel
Tazel
It won''t compile? Then why do error checking that way?



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Tazel
Tazel
Never mind. I just saw Sneftel said that it''s checking if it''s FALSE.



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Tazel
Tazel
now, "if(!blah)" expands to "if(!foo && myfunc(4))", but "if(!(blah))" expands to "if(!(foo && myfunc(4)))"

Again, wouldn''t that be the same thing?



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Palidine
Palidine
quote:
Original post by Tazel
Again, wouldn''t that be the same thing?



no.

"if(!foo && myfunc(4))" means if foo is false and myfunc(4) is true then execute the following logic


"if(!(foo && myfunc(4)))" means if BOTH foo and myfunc(4) are false then execute the following logic.

those are quite different

-me


felisandria
felisandria
No. You have to use order of operations.

"if(!blah)" expands to "if(!foo && myfunc(4))"

would resolve to "if foo is not true, and myfunc(4) is true"

"if(!(blah))" expands to "if(!(foo && myfunc(4)))"

would resolve to "the opposite of the result of checking if foo and myfunc(4) are both true".

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Tazel
Tazel
I see. So that happens when there are more than one things being evaluated.



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
aftermath
aftermath
the parens tell the operand ( ''!'' in this case ) what context to evaluate.

Rate me up.
felisandria
felisandria
You understand Order of Operations, right Tazel? You know that

2 + 1 * 6 is different than
(2 + 1) * 6 ?

We just added some more operations into the order of operations, that you might not be used to. So, when in doubt, use more parenthesis. Or look up "operator precedence" and see what tier it''s on.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Thunder_Hawk
Thunder_Hawk
This is why, if you feel the need to use macros, you must make liberal use of parentheses in the macro if it starts to gain much any kind of complexity, unless it''s the intended behaviour.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
Stoffel
Stoffel
!(a && b) is equivalent to (!a || !b)

Knowing a little boolean logic can get you pretty far in programming. Example:

(a || (!a && b)) is equivalent to (a || b), and easier to read if using long variable names.

Think Liberally..
Tazel
Tazel
Fel: Yes. The parentheses and any grouping symbol''s contents are evaluated first.

Then powers.

Then multiplication and division from left to right.

Then add. and sub. from left to right.



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.