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.
The single quote character (') may be used to indicate a comment and may appear after other keywords on a source line. The rest of the statement will be treated as a comment.
A source code statement beginning with Rem indicates that the rest of the line is comment and will not be compiled. Rem behavior is the same as above, except it must be the first keyword in the statement.
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).
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.
A multi-line comment can contain other multi-line comments inside it. Each inner comment has its own open- and close-comment markers.
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.
A single-line comment may appear after the line continuation 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.
Metacommands, such as $Static and $Include, can be placed in single-line comments. The $ sign and the keyword must be the first two things in the statement, not including white space.
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 parsing the single-line comment, put another single 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.
Single Line comments
The single quote character (') may be used to indicate a comment and may appear after other keywords on a source line. The rest of the statement will be treated as a comment.
' comment text
The comment statement: Rem
A source code statement beginning with Rem indicates that the rest of the line is comment and will not be compiled. Rem behavior is the same as above, except it must be the first keyword in the statement.
Rem comment
Multi-line 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"
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 multi-line comment can contain other multi-line comments inside it. Each inner comment has its own open- and close-comment markers.
/'
This is a comment.
/'
This is a comment inside a comment
'/
This Is a comment.
'/
This is a comment.
/'
This is a comment inside a comment
'/
This 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 continuation 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"
"This is part of the previous line's statement"
Metacommands
Metacommands, such as $Static and $Include, can be placed in single-line comments. The $ sign and the keyword must be the first two things in the statement, not including white space.
Rem compile With -lang fblite Or qb
#lang "fblite"
Rem $Static
' $include: 'vbcompat.bi'
#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 parsing the single-line comment, put another single 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."
'' this multiline comment marker ("/'") will be ignored
Print "This line is not a comment."
Example
/' this is a multi line
comment as a header of
this example '/
Rem This Is a Single Line comment
'this is a single line comment
Dim a As Integer 'comment following a statement
Dim b As /' can comment in here also '/ Integer
#if 0
before version 0.16, This was the
only way of commenting Out sections
With multiple lines of code.
#endif
comment as a header of
this example '/
Rem This Is a Single Line comment
'this is a single line comment
Dim a As Integer 'comment following a statement
Dim b As /' can comment in here also '/ Integer
#if 0
before version 0.16, This was the
only way of commenting Out sections
With multiple lines of code.
#endif
See also