Compile-time statements
$if
expression
$if
expression is a special compile-time if
expression that can be used to
detect an OS, compiler, platform, or compilation options.
It can also be used
to check the types of fields or methods when iterating them, see
Compile-time Reflection.
It can also specify different code depending on the type in generic functions,
see
Generics.
It supports multiple conditions in one branch:
Can be used as an expression:
Can have $else-$if
and $else
branches:
It can be used to check compilation options:
Custom compiler options
passed via -d
can be checked with $if option ? {}
:
Below are all the main supported options:
OS | Compilers | Platforms | Other |
---|---|---|---|
windows , linux , macos , |
gcc , tinyc , |
amd64 , arm64 |
debug , prod , test |
mac , darwin , ios , |
clang , mingw , |
x64 , x32 , |
js , glibc , prealloc |
android , mach , dragonfly , |
msvc , |
little_endian , |
no_bounds_checking , freestanding , |
gnu , hpux , haiku , qnx |
cplusplus |
big_endian |
no_segfault_handler , no_backtrace , |
solaris , termux |
no_main |
$for
statement
$for
allows you to iterate over special arrays, currently arrays for fields of
structures, methods of types, attributes of types and other.
Currently,
break
andcontinue
cannot be used inside$for
.
See the Compile-time Reflection article for more details.