Preprocessor
The Preprocessor performs some processing on source code before the next step of compilation.
The preprocessor is a program that parses a text file and makes it submit to certain transformations.
These transformations can be the inclusion of a file, the deletion of a text block or the replacement of a text block.
The preprocessor performs these operations through specific commands that it reads in the file being scanned.
It is automatically called by the compiler, before compilation, to process the files to compile.
Preprocessor commands
All preprocessor commands begin at the beginning of the line with the pound sign ("#").
See 'Preprocessor commands' to get all commands that control the preprocessor.
The main types of commands are the followings:
See 'Preprocessor commands' to get all commands that control the preprocessor.
The main types of commands are the followings:
- File inclusion:
- Text replacement:
- Compilation constants and conditional compilation:
- Macros:
- Other commands:
Text file inclusion allows you to factorize text that is common to many other files (for example, type, constant, function, etc.).
The common text is usually put in a file with the extension ".bi".
Syntax:
The included file is also processed by the preprocessor.
File inclusion also allows to include a library in the linking process.
Syntax:
The common text is usually put in a file with the extension ".bi".
Syntax:
The included file is also processed by the preprocessor.
File inclusion also allows to include a library in the linking process.
Syntax:
The preprocessor makes it possible to define identifiers which, used in the program, will be replaced textually by their value.
Syntax:
Defines are scoped (they are only visible in the scope they were defined in).
Namespaces on the other hand do not have any effect on the visibility of the defines.
Syntax:
#define identifier body
Whenever the identifier identifier is encountered by the preprocessor, it will be replaced by the text body throughout the rest of the program (#undef identifier to undefine an identifier previously defined).
where identifier is the identifier that will be used in the rest of the program, and body will be the replacement text that the preprocessor will use.
Defines are scoped (they are only visible in the scope they were defined in).
Namespaces on the other hand do not have any effect on the visibility of the defines.
The preprocessor is able to perform other actions than those mentioned above.
The directives for performing these actions are listed below:
The directives for performing these actions are listed below:
- #assert condition (conditional directive for debugging)
- #error error_text (directive for displaying error message)
- #lang "lang" (directive to set compiler dialect)
- #libpath "path" (directive to add search path for libraries)
- #line number ["name"](directive to set current line number [and file name])
- #pragma / #cmdline (directive to set compiler options)
- #pragma reserve (directive to reserve symbol name)
- #print text (directive to print text)
- #error error_text (directive for displaying error message)
- #lang "lang" (directive to set compiler dialect)
- #libpath "path" (directive to add search path for libraries)
- #line number ["name"](directive to set current line number [and file name])
- #pragma / #cmdline (directive to set compiler options)
- #pragma reserve (directive to reserve symbol name)
- #print text (directive to print text)
Example
Example with #include and #define:
See also
#include "vbcompat.bi"
#define TEMPLATE "hh:mm:ss yyyy/mm/dd"
Dim As String * Len(TEMPLATE) hour_date
hour_date = Format(Now, TEMPLATE)
Print hour_date, "(" & TEMPLATE & ")"
Sleep
#define TEMPLATE "hh:mm:ss yyyy/mm/dd"
Dim As String * Len(TEMPLATE) hour_date
hour_date = Format(Now, TEMPLATE)
Print hour_date, "(" & TEMPLATE & ")"
Sleep
Back to Programmer's Guide