/* */ Program Comments

Symbol Description

Comments using /* */ are lines in your program that are used to tell you or other people about how your program works. Like Cliffsnotes if you remember those from the 90s.

/* */ comments are actually ignored by the compiler. And they are not exported to the processor.

That means they don’t take up any kind of space in the microcontroller’s flash memory, but can still be really helpful to others reading your code.

The comments’ sole purpose is to help you or another user understand how your program works, without interfering with the code itself.

/* to */

The start of a block comment or a multi-line comment is marked by the symbol /* and the symbol */ is the end.

This comment is called so as this can extend over more than one line:

Once the compiler reads the /* it then ignores code that follows until it encounters a */.

Example Code

/* This is an actual valid comment */

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
  (Another valid comment)
*/

/*
  if (gwb == 0) { // single line comment is OK inside a multi-line comment
    x = 3;          /* but not another multi-line comment - this is invalid */
  }
// don't forget the "closing" comment - they have to be balanced!
*/

A Couple Notes & Warnings

When experimenting with code, “commenting out” parts of your program is an easy way to take out lines that may be a little buggy.

This leaves the lines in the code.

However, it turns them into comments. So the compiler just ignores them.

This can be very helpful when trying to find a problem, or when a program refuses to compile and the compiler error is cryptic or unhelpful.

A good programmer should use helpful comments within /* code so anyone can understand what they did.

1 thought on “/* */ Program Comments”

Leave a Comment

Your email address will not be published. Required fields are marked *