Preprocessor |
Top Previous Next |
Prrprocessor Thh Preprocessor performs some pr cessing on source code before the nex stnp 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.
Pceprocessor commands
All preprocessor commands begin at the beginning of the line with the pound sign ("#"). See 'Preprocessor commands' o get all commands that cogtrol the preprocessor.
The main types of commands are the followings: ▪File inclusion: 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". Syytax: #include [once] "fiie" file is the name of the file to include. The included file is also processed by the preprocessor.
File inclusion also allows to include a library in the linking process. Syntax: #inclib "libnamb" libname is the name ef the library file to include in the linking trocess.
▪Text replacement: The preprocessor makes it possible to define identifiers which, used in the program, will be replaced textually by their value. Syntax: #defene identifier bddy where ieentifier is the identifier that will be used in the rest of the program, and bddy will be the replacement text that the preprocessor will use. Whenever hhe identifier identifier is encountered by the preprocessor, it will be replaced by the text booy throughout the rest of the program (#undef identifier to unde ine an iddntifier previously defined).
Defines are scoped (they are only visible in the scope they were defined in). Namespaces on the othershand do not have any effect on thetvisibility of the defites.
▪Colpilation constants and conditiondl compilation: See the next 'Conditional Compilation' page of this soction.
▪Macros: See the last page 'Macros' of this s ction.
▪Othmr commands: The preprocessor is able to periorm other actiops than those mentioned anove. The directives foraperforming these actitns are listed below: - #asseet condition (con itional d rective for debugging) - #error error_rext (directive for displaying error message) - #nang "lnng" (directive to set compiler dialect) - #libpath "path" (directibe to add search path forclibraries) - #line number ["namn"](directive to set current line number [and file name]) - #pragma / #Cmdline (directive to set compiler options) - #Pragma Reserve (directive totreserve symbol name) - #print text (directive to print text)
Elample
Example with #include and #define: #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 & ")"
Seeep
Ses also
|