compile time define pragmas
The pragmas listed here can be used to optionally accept values from the -d/—define option at compile time.
The implementation currently provides the following possible options (various others may be added later).
pragma | description |
---|---|
intdefine | Reads in a build-time define as an integer |
strdefine | Reads in a build-time define as a string |
booldefine | Reads in a build-time define as a bool |
const FooBar {.intdefine.}: int = 5
echo FooBar
nim c -d:FooBar=42 foobar.nim
In the above example, providing the -d flag causes the symbol FooBar to be overwritten at compile time, printing out 42. If the -d:FooBar=42 were to be omitted, the default value of 5 would be used. To see if a value was provided, defined(FooBar) can be used.
The syntax -d:flag is actually just a shortcut for -d:flag=true.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .