Comments are pieces of the source code which are completely discarded by the compiler. They exist only for the benefit of the programmer, so he can explain certain pieces of code. For the compiler, it is as if the comments were not present.
The following piece of code demonstrates a comment:
The use of (* and *) as comment delimiters dates from the very first days of the Pascal language. It has been replaced mostly by the use of { and } as comment delimiters, as in the following example:
The comment can also span multiple lines:
Single line comments can also be made with the // delimiter:
The comment extends from the // character till the end of the line. This kind of comment was introduced by Borland in the Delphi Pascal compiler.
Free Pascal supports the use of nested comments. The following constructs are valid comments:
The following are valid ways of nesting comments:
The last two comments must be on one line. The following two will give errors:
and
The compiler will react with a “invalid character” error when it encounters such constructs, regardless of the -Mtp switch.
Remark In TP and Delphi mode, nested comments are not allowed, for maximum compatibility with existing code for those compilers.