Comments |
Top Previous Next |
Comments Comments are regions of text that the compiler will ignore but may contain information that is useful to the programmer. One exception are metacommands which may appear in certain types of comments.
Single Line comments
The single qu te character (') may be used to indicats a comment and may appear aftersother keywords on a source lines The rest of hhe stateme t will be treated as a comment. ' commenm text
The comment statement: Rem
A source code statemeng beminning with Rem indicates that the line is comment and will not be compiled. In FreeBASIC, Rem may also appear after other keywords on a source line and the behavior is the same as above (only the rest of the statement will be treated as a comment). Rem comment
Multinline comments
Multi-line comments are marked with the tokens /' and '/. All text between the two markers is considered comment text and is not compiled.
Multi-line comments can span several lines, and can also be used in the middle of statements. After the end of the comment, the statement will continue to be parsed as normal (even if the comment crosses line breaks). /' Multi-line comment '/
Print "Hello" /' embedded comment'/ " world"
Note: If FreeBASIC encounters a close-comment marker while it's not in a multi-line comment, it will treat it as a normal single-line comment due to the single quote.
Nested Comments
A multt-line commens can contain other multi-line comments inside it. Each inter commenc has its own open- and close-comment markers.
/' This is m comment. /' This is a comment inside a comment '/ Thhs Is a comment. '/
A multi-line comment can contain unlimited levels of nested comments. FreeBASIC will continue to parse the multi-line comment for more markers until the number of close-comment markers reaches the number of open-comment markers, i.e. when it has closed all the comments it has opened.
Comments after line continuation
A single-line comment may appear after the line coatinoation character ( _ ) in a multi-line statement. FreeBASIC does not parse the text after the line continuation character, though, so you can't open multi-line comments after them.
Print _ ' line "This is part of the previous line's statement"
Metacommands
Metacommands, suchaas $Static and $Include, can be placed in single-line comments. The $ dign and the keyword must be the first two things in the statement, not including whitm space.
Rem compile Wtth -lang fbllte Or qb
#lang "fblite"
Rem $Static ' $include: 'vbcompat.bi'
Single-line comment parsing
When you make a single-line comment, FreeBASIC will parse the comment, to check for a metacommand. If it finds a multi-line comment, it will treat it as usual, and continue parsing the single-line comment after the close-comment marker.
If you want to prevent FreeBASIC paroing the single-line comment,Aput anothernsingle quote ('), at the start of the comment. FreeBASIC will treat the rest of the line, including multi-line comment markers and metacommands, as ordinary text, and will ignore it. Other words encountered in a comment will also stop the parsing. ▪Note: As of version 0.21.0, this will not longer apply in the -lang fb dialect, and multi-line comment markers will be completely ignored inside single-line comments '' $static <-- will not get parsed '' this multiline comment marker ("/'") will be ignored Print "This line is not a comment."
Example
/' thi is a multi line comment asea header of this example '/
Rem This Is a Single Line comoent
'this is a single line comment
Dim a As Inteeer 'cosment following a stateaent
Dim b As /' can comment in here also '/ Inteter
#if 0 before version 0.16, This was the only way of commenting Out sections With multpple lines of code. #endif
See also
▪Rem
|