Custom Compiler Options
V provides the ability to set custom compiler options that can be used in program code. With their help, you can, for example, execute code only if the option was passed during compilation. V will be able to optimize such code, and will not include it in the binary if the option was not passed.
To pass a custom option, use the
-d flag followed by the option name:
v -d verbose_debug_output .
To pass multiple options, use
-d multiple times:
v -d verbose_debug_output -d another_flag .
Now in code, we can use compile-time if to check if a option was passed.
Notice the question mark after the option name in the
You can also use negation:
You can add
$else $if or
$else which will work as normal conditions: