Go Down

Topic: Two ideas (Read 2992 times) previous topic - next topic


0, I believe... ?

Or am I not understanding your question?

Or was it not directed at me? :-)



Code: [Select]

int foo;
if (foo = getSomeValue()) {
  int bar = doSomethingWithFoo(foo);

What that is doing is basically this:


Code: [Select]

int foo = getSomeValue();
if (foo) {
  int bar = doSomethingWithFoo(foo);

It's checking to see if foo is true (not false, false = 0).
So it's deciding if foo = getsomevalue() ,which can be said is just foo (as you're simply telling it what foo is), is true.

It's annoying to debug and normally people mean to use == in those situations so generally you wouldn't use that 'shortened version' for anything.


I'm gonna force my buddy to write a app

Maybe you could coerce him/her to include a grammar and spelling checker.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up