PBXB64 V21

#OVERRIDE & Preprocessor

#OVERRIDE replaces a registered BASIC runtime call with a typed custom function body. This allows controlled adaptations and targeted instrumentation without rewriting every call in the program.

Typed replacement within the module

The definition is placed at module scope, starts with #OVERRIDE target(parameter AS type) AS returntype and ends with #ENDOVERRIDE. This function example sets FUNCTION in its body. The compiler checks the registered target contract and parameter/return types. Separate source rules also cover registered statement and operator targets; not every name is an eligible target.

#OVERRIDE is distinct from ordinary macro text replacement and the OVERRIDE method keyword in classes. Preprocessor directives such as #IF and user-defined symbols are excluded as targets. It does not globally replace an operating-system function either. The definition belongs to the compiled module rather than acting as a global switch for other programs.

Example: deliberately customize ABS

override.pb
' A module-scope catalog override remains dispatchable after scope tracking. #OVERRIDE ABS(value AS LONG) AS LONG FUNCTION = value + 40 #ENDOVERRIDE FUNCTION PBMAIN() AS LONG IF ABS(2) <> 42 THEN FUNCTION = 1 : EXIT FUNCTION FUNCTION = 0 END FUNCTION

Compiled and executed with shipped V21 on 2026-09-30: ABS(2) deliberately returns 42 here. This intentionally changes semantics rather than preserving mathematical ABS. A separate negative #OVERRIDE #IF test was rejected with diagnostic 4125 and produced no executable.

Open checked source

Preprocessor: selection and reuse before compilation

The separate BASIC preprocessor handles file inclusion with #INCLUDE, object-like and function-like #DEFINE macros, conditional branches with #IF / #ELSE / #ENDIF, and repeated source generation with #REPEAT / #ENDREPEAT. The driver provides -E, -I, -D and -U for preprocessing output, include paths and command-line definitions.

This processing occurs before the BASIC frontend. #OVERRIDE instead replaces a typed runtime call; the two tools have different scopes.

Example: include, macro, condition and repetition

preprocessor.pb
#COMPILE EXE #DIM ALL #INCLUDE "web-defines.inc" #DEFINE ADD(left, right) = left + right #REPEAT 3 AS %INDEX #IF %INDEX = 2 #DEFINE SELECTED 40 #ENDIF #ENDREPEAT FUNCTION PBMAIN() AS LONG #IF ENABLE_WEB_CHECK = 1 IF ADD(SELECTED, 2) <> 42 THEN PBMAIN = 1 : EXIT FUNCTION #ELSE PBMAIN = 2 : EXIT FUNCTION #ENDIF PBMAIN = 0 END FUNCTION

V21: compiled and executed natively. The %INDEX = 2 branch sets SELECTED to 40; ADD(SELECTED, 2) must equal 42. The selected #IF branch is checked; failures return 1 or 2.

Open checked source

web-defines.inc

#DEFINE ENABLE_WEB_CHECK 1
Open include as text

The include file is part of the checked example. Save this text as web-defines.inc alongside preprocessor.pb.

Supported by the current #OVERRIDE collector, existing contract cases and the stated short V21 checks. This single example does not fully qualify every overload, operator or statement variation.

View verification receiptsX-Code
Back to feature list