#INCLUDE Directive
Syntax:
#INCLUDE "filename"#INCLUDE ONCE "filename"
Description
The #INCLUDE directive inserts the contents of another source file at the point where the directive appears. This is the primary mechanism for modular code organization, API declarations, and type sharing in PBXA64.
The included file is treated as if its content were physically pasted into the including file at the exact location of the #INCLUDE line. Included files typically use the .inc extension but any text file is accepted.
The optional ONCE keyword prevents the file from being included more than once in a single compilation unit, guarding against duplicate declarations. This is equivalent to C's #pragma once.
Parameters
| Parameter | Description |
|---|---|
ONCE | Optional keyword. Ensures the file is included only once per compilation, even if #INCLUDE for this file appears in multiple locations (e.g., through nested includes). |
"filename" | The path and filename of the file to include, enclosed in double quotes. Relative paths are resolved against the directory containing the current source file. Absolute paths are also accepted. |
Example
' Include Windows API declarations (once)
#INCLUDE ONCE "Win32API.inc"
' Include project constants
#INCLUDE "MyProject_Constants.inc"
' Include utility functions
#INCLUDE "MyUtils.inc"
FUNCTION PBMAIN() AS LONG
LOCAL hWnd AS DWORD
hWnd = GetConsoleWindow()
PRINT "Console handle: "; hWnd
FUNCTION = 0
END FUNCTION
Notes
- PBXA64 searches for included files in the following order: (1) the directory of the current source file, (2) directories specified via compiler include paths, (3) the compiler's built-in include directory.
- Nested includes are supported but care should be taken to avoid circular dependencies.
- Use
#INCLUDE ONCEfor header-style files that declare types, constants, and API functions to prevent redefinition errors. - PBXA64 does not support angle-bracket include syntax (
<file>). Always use double quotes. - PBXA64 does not support
#RESOURCEdirective; use#INCLUDEwith resource script files if needed.