@cImport
@cImport
@cImport(expression) type
This function parses C code and imports the functions, types, variables, and compatible macro definitions into a new empty struct type, and then returns that type.
expression is interpreted at compile time. The builtin functions @cInclude, @cDefine, and @cUndef work within this expression, appending to a temporary buffer which is then parsed as C code.
Usually you should only have one @cImport in your entire application, because it saves the compiler from invoking clang multiple times, and prevents inline functions from being duplicated.
Reasons for having multiple @cImport expressions would be:
- To avoid a symbol collision, for example if foo.h and bar.h both
#define CONNECTION_COUNT - To analyze the C code with different preprocessor defines
See also:
- Import from C Header File
- @cInclude
- @cDefine
- @cUndef
