WARNING: assigning type in the middle of code: Don't (Also, heed warnings)

OK, I should know better, but for those that don't, I'll post this warning:

Don't assign a type and value to a variable in the middle of your code. Results may vary. I did something like this:

.
.
.
boolean temp = gnarlyBooleanFunction(stoopidVariable);
if (temp) print("it's cool"); else print("not cool, dude);
.
.
.

Talk about going off into la-la land! I thought my uno was on drugs!

Another psychedelic drug for uno is ignoring the compiler warning when your program is pushing the limits.

uno IDE 1.8.4 windows 10 64bit

...so what's the problem? There's nothing wrong with that snippet there.

Jiggy-Ninja:
There's nothing wrong with that snippet there.

... apart from a missing double quote:

else print("not cool, dude);

I've written some pretty complex code for the Arduino and I've never had a problem declaring variables anywhere that is legal. As a matter of practice, I always declare variables just before I use them; consequently this means they can easily be in the beginning, middle, or end of code blocks.

As for warnings, my Arduino preferences are set for compiler warnings: all. I find them very useful for getting rid of sloppy programming. For me, they have never been wrong.

Don't assign a type and value to a variable in the middle of your code.

boolean temp = gnarlyBooleanFunction(stoopidVariable);
if (temp) print("it's cool"); else print("not cool, dude");

Did you by any chance already have a global variable named temp ?

I don't believe I did. but I will look at that!

When I changed the code to

bool temp;
temp = gnarlyBooleanFunction(stoopidVariable);

The problem went away.

(OK, it wasn't my exact code. And yes, I forgot my closing quote in my comments here; the compiler would have caught that!)

Please provide two complete programs, one with the problem and one without, that demonstrates the problem that you're seeing. There must be more going on than what little you've posted (e.g., undefined behavior).

OldSurferDude:
I don't believe I did. but I will look at that!

When I changed the code to

bool temp;
temp = gnarlyBooleanFunction(stoopidVariable);

The problem went away.

(OK, it wasn't my exact code. And yes, I forgot my closing quote in my comments here; the compiler would have caught that!)

That makes absolutely no sense. You must have changed something else that fixed the problem, or there's some other, vastly more subtle error in whatever code you aren't posting.

You haven't even said what went wrong, just that the Arduino went "off into a la-la land!" I cannot imagine what problem would be caused by your original snippet that would be fixed by this one.