procedure CompilerAssert (Condition: Boolean);
or
function CompilerAssert (Condition: Boolean): Boolean;
or
function CompilerAssert (Condition: Boolean;
ResultValue: Any_Type): type of ResultValue;
CompilerAssert checks the given Condition at compile-time. If it is a compile-time constant of Boolean type with the value True, it returns ResultValue, or if called with only one argument, it returns True or nothing if used as a procedure.
If Condition cannot be evaluated at compile-time or does not have the value True, it causes a compile-time error.
So it can be used to make sure that certain assumptions hold before relying on them.
CompilerAssert does not depend on the --[no-]assertions options. It does not generate any run-time code.
CompilerAssert is a GNU Pascal extension.
program CompilerAssertDemo;
var
a: LongInt;
const
{ Make sure that the highest value a can hold is larger than
MaxInt, and set b to that value. }
b = CompilerAssert (High (a) > MaxInt, High (a));
{ Do a similar check for the minimum value, setting c to True
(which can be ignored). }
c = CompilerAssert (Low (a) < Low (Integer));
begin
{ Procedure-like use of CompilerAssert in the statement part. }
CompilerAssert (MaxInt >= 100000);
WriteLn (b, ' ', c)
end.