Strange, but trivial, issue...

Hi guys,
So I ran into a weird problem, that I solved, but thought I might mention to the many Arduino users.
I like to comment my code and since I am the only user, I often include “helpful” comments often containing humor. This led me to run into the " !!! " error seen on the MEGA 2560 boards but that was months ago. Now I’m using the MEGA to control some L298 H-bridges (4) to control 4 motors (channels are bridged to obtain ~ 4A current to each motor and is irrelevant).
Today, I ran into this problem which I cannot find any info on… Here is this bad code:

  digitalWrite(RR_Motor_Pin1,LOW);//  \
  digitalWrite(RR_Motor_Pin2,HIGH);//  \ 
                                   //   >  SHOULD BE THE SAME FOR SPINNING MOVEMENTS
  digitalWrite(FR_Motor_Pin1,LOW);//   / 
  digitalWrite(FR_Motor_Pin2,HIGH);// /

in which RR_Motor_Pin1 = pin 12
RR_Motor_Pin2 = pin 13.
FR_Motor_Pin1 = pin 12
FR_Motor_Pin2 = pin 13.

With the comments in the code, the digitalWrite for RR_Motor_Pin2 doesn’t happen but they do for the FR_Motor_Pins. Remove the comments and everything works fine. Weird right…?

I’d love to hear some input on this if anyone knows… Moral of the story: "Stick to simple comments which don’t contain many (if any) symbols!!! <---- :stuck_out_tongue:

maybe posting the whole code gives more clues ...

Not weird at all.... the \ is a continuation character, so a comment ending on \ means the comment continues on the next line, ie the next line of real code is taken as a comment.

Well then.... I guess it is really not weird at all. I was taught that the "//" comments the rest of the line regardless of the following characters... This is obviously not correct. Thanks for the fast reply JimboZA

I was taught that the "//" comments the rest of the line regardless of the following characters... This is obviously not correct

It is obviously exactly correct.

The other moral is do not use ascii art in your comments - just use inline comments. There are just too many ways for it to go wrong, especially when line wrapping is introduced and editors start playing games with indentation and whitespace.

AWOL, might you explain your answer a little more? If the "//" comments out the rest of the line and the "\" is part of that line then why doesn't it treat it like a comment?

and on a side note (not trying to take a shot at you!) your quote should be... "Pete, its a fool "that" looks for logic in the chambers of the human heart." Great movie too!

if the "//" comments out the rest of the line and the "\" is part of that line then why doesn't it treat it like a comment?

It does treat the rest of the line as a comment, and because it has a continuation character, it treats the next line as part of that comment.

your quote should be

And Neil Armstrong should have slipped in an "a", but didn't. Maybe it is just Clooney's diction, but I can't hear a "that", though obviously I know it should be there. Maybe it is Southern dialect. http://www.youtube.com/watch?v=WQeh132J7gE

C++ has what is know as phases of translation, that governs the order in which things are processed. http://en.cppreference.com/w/cpp/language/translation_phases. C has a similar phases of translation.

Phase 1 is when digraphs and trigraphs are processed. In particular, ??/ is converted to a backslash (****). You probably want to be careful of ?? any where in the source, including in comments and strings. Trigraphs were added to C in the 1989/1990 standard due to the use at the time of 7-bit character sets where several of the characters used by the C language where replaced with national characters (o with umlats for example). I was on the ANSI C standards committee at the time, and the politics were interesting. Digraphs were later added to the first C++ standard.

Phase 2 is when ‘’ in front of an end of line character is deleted along with the end of line character.

Phase 3 is when comments are replaced by a single space. So while it may be counter-intuitive, that is what the standard calls for.

Thank you both for your replies... I didn't understand that the "//" characters had other characters which would be associated with that line. That being said, show I also be careful of what I but between the /* *\ comment designations?

P.S.-- "AWOL" touche buddy.. I guess I need to watch what I say around you... :zipper_mouth_face: Darn southern dialect!

PeterH: The other moral is do not use ascii art in your comments - just use inline comments. There are just too many ways for it to go wrong, especially when line wrapping is introduced and editors start playing games with indentation and whitespace.

Ascii art is pretty lame. However for arduino projects it would be kind of cool if you could embed in comments somehow a schematic drawing of the sketch it is using.

retrolefty: Ascii art is pretty lame. However for arduino projects it would be kind of cool if you could embed in comments somehow a schematic drawing of the sketch it is using.

Known in encryption circles as "sketchanography"

rglazebr:
Thank you both for your replies… I didn’t understand that the “//” characters had other characters which would be associated with that line. That being said, show I also be careful of what I but between the /* *\ comment designations?

P.S.-- “AWOL” touche buddy… I guess I need to watch what I say around you… :zipper_mouth_face: Darn southern dialect!

The C-style comments are /* … */ not /* … __, i.e. forward slash on both sides. It does not end with back slash like you mention. In terms of stuff in __/ … */, none of the trigraphs and digraphs have an asterisk as the last character, so you don’t have to worry about using those inside C-style comments.

I will note that a lot of people hate trigraphs, and in fact recent versions of GCC only enable them when you are in strict standards compliance mode.

I do like the schematic art idea... otherwise, I don't go all out with "art"... but many of my autonomous robot sketches have a large list of comments on the top describing the particular values associated and why.. (this allows me to make adjustments easily)..

Note to self though... use as few symbols as possible.. :0

In hindsight, this thread should have been named, "ASCII Art"... seems appropriate!

Yup, i'm a putz but going to say it was a typo... :D You seem bright Mr. Meissner. Thanks for teaching me something.