Skip to main content

Attributes Reference

Attributes in Zynx provide metadata to the compiler, influencing semantic analysis, linting, and C code generation.

This reference lists the most commonly used attributes and how they affect backend lowering and compile-time behavior.

Attributes are used together with:

  • Types – attributes that affect layout and visibility.
  • Structs – struct methods, init/drop, and field constraints.
  • Control Flow – attributes that influence analysis around branching and testing.
  • C Interoperability Overview – ABI and representation attributes at the C boundary.

Function Attributes

AttributeDescriptionC Backend Mapping
@inlineHints to the compiler to inline the function.inline
@discardableSuppresses unused-result warnings for calls to this function.Analysis only.
@deprecatedMarks API as deprecated; emits a warning on use.Analysis only.
@weakMarks the symbol as weak.__attribute__((weak))
@noreturnIndicates that the function does not return to its caller._Noreturn
@section("name")Places the function in a specific object file section.__attribute__((section("name")))

Type / ABI Attributes

AttributeDescriptionC Backend Mapping / Effect
@nativeUses C layout/ABI representation where applicable (structs/enums/errors). On structs, it also implies strict field order.C-compatible representation.
@strictDisables struct field reordering optimization for non-@native structs.Layout fixed to source order.
@c_name("...")Overrides emitted symbol/type name for interop declarations.Uses provided C name.

Struct and Field Attributes

AttributeDescriptionC Backend Mapping
@packedRemoves padding between struct members.__attribute__((packed))
@align(N)Sets the minimum alignment for the structure.__attribute__((aligned(N)))
@privateRestricts field access to the struct's own methods.Internal (Analysis only).
@readonlyField is mutable only inside the struct's own methods.Internal (Analysis only).
@bits(N)Sets bit width for a field in @native structs.Bitfield width in header/code

Diagnostic Control Attributes

AttributeDescriptionScope
@unusedSuppresses unused-variable warnings for a declaration.Decl
@suppress("...")Suppresses selected analyzer warnings (for example "deprecated").Decl / Func / Top-level

Target Filtering

Use @abi, @arch, and @platform to write target-specific code. If an AST node does not match the compiler's current target settings, it is removed before analysis. This enables small, explicit variations without littering the code with preprocessor directives.

Supported Values

  • @platform: "linux", "darwin", "windows".
  • @arch: "x86_64", "aarch64", "riscv64".
  • @abi: "gnu", "apple", "msvc", "musl".
@platform("linux")
fn socket() { ... }

@platform("windows")
fn socket() { ... }

Only the version matching the current target platform will exist in the final binary.

Notes

  • Unknown attributes are warned by default.
  • @suppress("unknown_attribute") can silence unknown-attribute warnings.