Compiler functions
These look like functions, but the compiler evaluates them itself. They cost nothing when the program runs.
SizeOf ✅
size = SizeOf(type-or-variable)
The size in bytes of a type, a structure, or a variable.
Structure Pixel
r.a
g.a
b.a
EndStructure
OpenConsole()
x.d = 1
PrintN(Str(SizeOf(Pixel)) + " " + Str(SizeOf(long)) + " " + Str(SizeOf(x)) + " " + Str(SizeOf(char)))
Output:
3 4 8 2
Bool ✅
result = Bool(condition)
Gives 1 if the condition is true, otherwise 0. In x, a comparison already gives 0 or 1, so Bool is only needed for PureBasic compatibility, or to turn any number into 0 or 1.
OpenConsole()
n = 5
PrintN(Str(Bool(n > 3)) + Str(Bool(n)) + Str(Bool(0)))
Output:
110
OffsetOf ✅
offset = OffsetOf(Structure\Field)
The position of a field inside a structure, in bytes. Fields of nested structures work too: OffsetOf(Line\a\y). PureBasic structures are packed (no padding) unless they use Align.
TypeOf ✅
type = TypeOf(variable-or-Structure\Field)
A constant naming the type: #PB_Byte, #PB_Ascii, #PB_Word, #PB_Unicode, #PB_Character, #PB_Long, #PB_Integer, #PB_Quad, #PB_Float, #PB_Double or #PB_String. Its main use is with SortStructuredArray, together with OffsetOf.
Structure Pixel
x.w
y.w
colour.l
name$
EndStructure
OpenConsole()
v.d = 1.5
PrintN(Str(OffsetOf(Pixel\y)) + " " + Str(OffsetOf(Pixel\colour)) + " " + Str(OffsetOf(Pixel\name$)))
PrintN(Str(Bool(TypeOf(Pixel\colour) = #PB_Long)) + Str(Bool(TypeOf(v) = #PB_Double)) + Str(Bool(TypeOf(Pixel\name$) = #PB_String)))
Output:
2 4 8
111
Planned 🔜
| Function | Gives |
|---|---|
Defined(name, kind) |
whether a name is defined |
Subsystem(name) |
whether a subsystem was selected |