Compiler Functions
DescriptionSize = SizeOf(Type)
SizeOf can be used to find out the size of any complex Structure (it does not work on the simple built-in types such as word and float), Interface or even variables. This can be useful in many areas such as calculating memory requirements for operations, using API commands, etc.
Note: In unicode mode one character uses 2 bytes. In Ascii mode one character uses 1 byte. Sizeof(Character) allows to return the size (in bytes), which is taken by one character according to the active mode.Example:
Structure Person Name.s ForName.s Age.w EndStructure Debug "The size of my friend is "+Str(Sizeof(Person))+" bytes" ; will be 10 (4+4+2) John.Person\Name = "John" Debug SizeOf(John) ; will be also 10Note: if a variable and a structure have the same name, the structure will have the priority over the variable.
DescriptionIndex = OffsetOf(Structure\Field) Index = OffsetOf(Interface\Function())
OffsetOf can be used to find out the index of a Structure field or the index of an Interface function. When used with an Interface, the function index is the memory offset, so it will be IndexOfTheFunction*4.Example:
Structure Person Name.s ForName.s Age.w EndStructure Debug OffsetOf(Person\Age) ; will be 8 as a string is 4 byte in memory Interface ITest Create() Destroy(Flags) EndInterface Debug OffsetOf(ITest\Destroy()) ; will be 4
DescriptionResult = Subsystem(<constant string expression>)
Subsystem can be used to find out if a subsystem is in use for the program being compiled. The name of the subsystem is not case sensitive.Example:
CompilerIf Subsystem("OpenGL") Debug "Compiling with the OpenGL subsystem" CompilerEndIf
DescriptionResult = Defined(Name, Type)
Defined checks if a particular object of a code source like structure, interface, variables etc. is already defined or not. The 'Name' parameter has to be specified without any extra decoration (ie: without the '#' for a constant, without '()' for an array or a linkedlist).
The 'Type' parameter can be one of the following values:#PB_Constant #PB_Variable #PB_Array #PB_LinkedList #PB_Structure #PB_InterfaceExample:
#PureConstant = 10 CompilerIf Defined(PureConstant, #PB_Constant) Debug "Constant 'PureConstant' is already declared" CompilerEndIf Test = 25 CompilerIf Defined(Test, #PB_Variable) Debug "Variable 'Test' is already declared" CompilerEndIf