importc
Importc pragma
The importc
pragma provides a means to import a proc or a variable
from C. The optional argument is a string containing the C identifier.
If the argument is missing, the C name is the Nim identifier exactly as
spelled:
When importc
is applied to a let
statement it can omit its value
which will then be expected to come from C. This can be used to import a
C const
{.interpreted-text role="c"}:
Note that this pragma has been abused in the past to also work in the JS backend for JS objects and functions. Other backends do provide the same feature under the same name. Also, when the target language is not set to C, other pragmas are available:
In the example, the external name of p
is set to prefixp
. Only $1
is available and a literal dollar sign must be written as $$
.