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
| Attribute | Description | C Backend Mapping |
|---|---|---|
@inline | Hints to the compiler to inline the function. | inline |
@discardable | Suppresses unused-result warnings for calls to this function. | Analysis only. |
@deprecated | Marks API as deprecated; emits a warning on use. | Analysis only. |
@weak | Marks the symbol as weak. | __attribute__((weak)) |
@noreturn | Indicates 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
| Attribute | Description | C Backend Mapping / Effect |
|---|---|---|
@native | Uses C layout/ABI representation where applicable (structs/enums/errors). On structs, it also implies strict field order. | C-compatible representation. |
@strict | Disables 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
| Attribute | Description | C Backend Mapping |
|---|---|---|
@packed | Removes padding between struct members. | __attribute__((packed)) |
@align(N) | Sets the minimum alignment for the structure. | __attribute__((aligned(N))) |
@private | Restricts field access to the struct's own methods. | Internal (Analysis only). |
@readonly | Field 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
| Attribute | Description | Scope |
|---|---|---|
@unused | Suppresses 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.
Related Topics
- Type System – how attributes decorate types and declarations.
- Structs – where struct and field attributes are applied in practice.
- Control Flow – how attributes can be combined with tests and branching.
- C Interoperability Overview – representation attributes at the C boundary.
- Native Bindings Workflow – how attributes appear in generated bindings.