About
The MAXON API makes heavy use of C++ preprocessor macros. These macros are used to automatically create code or to mark parts of the code (e.g. in interfaces). The macros described on this page are relevant for every kind of development. Other specialised macros exist for special tasks.
Object Use
Under Xcode / GCC the compiler can check if the return value of a function is used or not. If a return value that should be used is not used, a compile error is thrown.
- Note
- Do not use these macros to mute errors returned with the error system. Instead use iferr_cannot_fail() or iferr_ignore(). See Error Handling.
- MAXON_WARN_UNUSED_CLASS: If a class marked with this macro is used as a return value but this return value is not used, an error is thrown.
{
};
static CriticalInfo GetCriticalInfo();
GetCriticalInfo();
const CriticalInfo info = GetCriticalInfo();
If a variable is declared but not used this will trigger a compile warning. This warning can be suppressed with this function:
- maxon::UseVariable(): Uses the given variable.
- Note
- Using maxon::UseVariable() will not cause any performance penalty.
{
}
{
maxon::UseVariable(number);
}
Program Flow and Structure
These macros are used to mark certain parts of the source code:
- MAXON_SCOPE: Marks a block of code that is scoped for a certain reason.
- MAXON_UNLIKELY: Marks an unlikely branch for branch prediction.
- MAXON_LIKELY: Marks a likely branch for branch prediction.
{
number++;
}
{
number++;
}
Switch-case statements can be improved with:
enum class MyEnum
{
A,
B,
C
};
const MyEnum value = MyEnum::B;
switch (value)
{
case MyEnum::A:
break;
case MyEnum::B:
break;
default:
break;
}
Finally
The code defined in a "finally" block is executed when the program flow leaves the current scope.
- finally: Defines a code block which is executed when the scope is left.
- finally_once: Returns a maxon::FinallyOnce object that can be used to disable the code block execution.
Enummerations
enum class PRIMARY_COLOR
{
enum class QUALITY
{
A = (1 << 0),
B = (1 << 1),
C = (1 << 2),
D = (1 << 3),
const QUALITY qualities = QUALITY::A | QUALITY::B;
if (qualities & QUALITY::A)
if (!(qualities & QUALITY::D))
Classes and Functions
The following macros are used to declare classes and their functions:
These macros are used to implement certain operators automatically:
class NumberClass
{
public:
{
_number = v;
}
{
return &_number;
}
{
}
private:
};
NumberClass someNumber(1);
maxon::Int*
const number = someNumber.GetNumber();
*number = *number + 1;
const maxon::Int*
const res = someNumber.GetNumber();
NumberClass someOtherNumber(0);
someOtherNumber = someNumber;
Utility
Other utility macros exist:
Further Reading