Attributes

An attribute attaches metadata to a declaration, written as an #Name(...) attribute call on the line before the item it annotates. Attributes instruct the compiler — to link a foreign library, fix a calling convention, or flag a function at its call sites — without changing the declaration's own code.

#Link("Kernel32.dll")
extern func Beep(freq: uint32, duration: uint32) -> bool32;

Multiple attributes may be stacked before a single declaration; each applies independently.

#NoReturn()
#Warn("prefer Exit(); Abort() skips destructors")
func Abort();

Available Attributes

AttributePurpose
#LinkLink an extern function to a native library
#AbiSelect a declaration's calling convention
#WarnEmit a compiler warning at every call site
#ErrorEmit a compiler error at every call site
#NoReturnDeclare that a function never returns to its caller
#AllowSuppress a specific lint on the declaration

Not an Attribute: Platform Selection

Restricting code to an operating system is not an attribute. Use conditional compilation instead — when #target.os == .Windows { ... } — which removes the untaken code before analysis rather than annotating a declaration.

See Also