DEBUG THIS

The worst possible thing to debug is an accidental ";" after an if statement. I'm just saying, because this mistake has just cost me about 12 hours of my life to figure it out... and possibly blowing a few deadlines.

You need to turn all warnings on in Preferences and always investigate every warning printed - lots of the warnings are benign but then there's one like this. This code:

  if(rand() == 10); {
    Serial.println(rand()+2);
  }

produced this warning:

C:\Users\Whoever\AppData\Local\Temp\arduino_modified_sketch_268981\sketch_oct25a.ino: In function 'void setup()':

C:\Users\Whoever\AppData\Local\Temp\arduino_modified_sketch_268981\sketch_oct25a.ino:26:19: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]

   if(rand() == 10); {

                   ^

Pete

When I write an IF I put in the {} before I put in the content. And I NEVER use single line IFs.

But I have also wasted hours on stupid mistakes.

...R

Oh, lots of things can bite you on the ass.
A misplaced backslash at the end of a // comment, a missed */ on a block comment, incorrect operator precedence . . .
Compiler warnings will get most of them though.

Robin2:
... I NEVER use single line IFs.
...

You should try it man! I'd liken it to the first time you took a shot of vodka, or stood up on a surfboard. Exhilarating!

Heh. Seriously though, I think there are circumstances they improve readability - but you need to expect them! Otherwise readers get confused when the } never comes. Semicolons should be bigger[b];[/b]

Double free. And its much nastier cousin, freeing an uninitialized pointer.

Buffer overruns / underruns are also fun.

Spent three days without sleep helping to debug a buffer overrun at ... uh ... let's called it a defunct pipeline company. Bruce forgot to account for the null terminator. It took about two hours from the overrun to the first symptom. Long stretches of waiting. And waiting. And waiting. Until the software finally crashed. Then we would postmortem, revise the theory, and start over.

Making the situation truly surreal was having to cram two (or three) people into desk space meant for a Yorkshire Terrier and Howard (boss) anxiously pacing back-and-forth on the squeaky raised floor under the buzzing fluorescent lights.

dally:
deadly syntax mistakes are a common problem due to the C grammar
e.g. "if (a=0)" … an assignment inside a conditional? cool idea!
wrong by design!

Such a shame you weren't around to advise K&R on their folly.

:grin:

dally:
e.g. "if (a=0)" … an assignment inside a conditional?

See reply #1.

dally:
I see obstinacy

That's odd, I see trolling.

because the grammer doesn't say a word about them

sp. "grammar". Oh, the ferrousness.

@dally - it doesn't really work when you redact already-quoted text.

Again, I see trolling.
You're a permanently common "relaxed" user, and contribute zero, nada, zippo, zilch, rien to the rest of the forum.

I'm unclear about your comments on obligation and customer care - I have no customers and no obligation.

dally:
I am out.

Promise?

sp. "Another"

dally:
deadly syntax mistakes are a common problem due to the C grammar
e.g. "if (a=0)" … an assignment inside a conditional? cool idea!
wrong by design!

It is just compound statement (an assignment and compare) - two in one. Many languages allows this, even more complicated syntax. Do you know e.g. the Power Shell? You can do mistakes in any language. I don't see an obstacle but opportunity to write more elegant code. I think, the C is perfect as is (it is improving) and it have been standing proof of time up to now. (sorry my English, if...).

AWOL:
Again, I see trolling.
...

I thought, it is "Bar Sport" section. 8)

Robin2:
When I write an IF I put in the {} before I put in the content. And I NEVER use single line IFs.

But I have also wasted hours on stupid mistakes.

...R

I always put {} in first as well, when I'm not using a single line if. I do not think I have ever had the issue of putting a semi-colon there. Nothing wrong with single line if's when they are small and sweet.

I have had plenty of errors from forgetting them at end of statements though.

dally:
deadly syntax mistakes are a common problem due to the C grammar
e.g. "if (a=0)" … an assignment inside a conditional? cool idea!
wrong by design!

If it was wrong, we wouldn't be able to assign scope local variables, and they can be useful in some cases:

if( int i = something ){

}

perigalacticon:
The worst possible thing to debug is an accidental ";" after an if statement. I'm just saying, because this mistake has just cost me about 12 hours of my life to figure it out... and possibly blowing a few deadlines.

That's just syntax. Wait until you get into serious runtime.

AWOL:
Such a shame you weren't around to advise K&R on their folly.

If K&R invented hammers, you'd be able to hit your thumb with one.

But they would be smaller, faster and more precise.

And the hits would hurt more.

And it would be a surprise, coming out of a library sight-unseen.