Go Down

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

tastewar

0, I believe... ?

Or am I not understanding your question?

Or was it not directed at me? :-)

mowcius

Quote

Code: [Select]

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


What that is doing is basically this:

Quote

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.

AWOL

Quote
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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy