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:
  • 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".
    #include [once] "file"
    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.
    #inclib "libname"
    libname is the name of the library file to include in the linking process.

  • Text replacement:
  • The preprocessor makes it possible to define identifiers which, used in the program, will be replaced textually by their value.
    #define identifier body
    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.
    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).

    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.

  • Compilation constants and conditional compilation:
  • See the next 'Conditional Compilation' page of this section.

  • Macros:
  • See the last page 'Macros' of this section.

  • Other commands:
  • The preprocessor is able to perform other actions than those mentioned above.
    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 ... (directive to set compiler options)
    - #print text (directive to print text)

Example with #include and #define:
#include ""
#define TEMPLATE "hh:mm:ss yyyy/mm/dd"

Dim As String * Len(TEMPLATE) hour_date

hour_date = Format(Now, TEMPLATE)

Print hour_date, "(" & TEMPLATE & ")"


See also
Back to Programmer's Guide
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode