Comments

There are two type of comments, the old and the new (from C++). The new style comment start with (two slashes):

	//
and goes to the end of the line including the new line character.

An old style comment starts with the two character sequence:

	/*

and ends with the two character sequence:

	*/

Such a comment can start on one line and end on another. There must be no white space between the slash and the asterisk.

A comment is allowed anywhere in a program that white space is allowed. And that is in between two tokens.

A comment is a sequence of characters in the source file, usually used to explain something. A comment can explain what a function does, what a variable is used for, what the next few statements in a function will do, etc.

There is no restriction on what characters can appear between the beginning and ending of a comment. That is any possible byte value, even those not in the 'C' source alphabet can be used.

Most compilers give a means (e.g. a software switch or menu option) which determines if comments can be nested or not. The default is for comments not to be nested. If comments can be nested, then the sequence:

	/* ... /* ... */ ... */

is a comment within a comment. If comment nesting is not allowed, then the first comment would end where the second, or innermost comment ends; and the end of the first (or outer most comment) the compiler would give an error. Nested comments is not portable - i.e. there may be compilers which do not allow nesting. There is no standard way to set or reset the nesting switch, it can be different for each compiler.

Comments are not only for others to read, but for oneself. Six months later, one may not remember how that clever little algorithm works unless the comments are there to jog the memory. Do not be afraid to write long multiple line comments - they will save you time in the long run.

Important comments, such as what a module does, or what a function does, are sometimes made very visible, like the following:

	/**********************************
	 * stuff, and words  ....         *
	 *  ...                           *
	 *                                *
	 * and more words.                *
	 **********************************/

© 1991-2008 Prem Sobel. All Rights Reserved.