Reflection
- There are several built-in functions to inspect the code during compile time.
.lenon arrays and slices returns their length.$defined(<expr>)returns true if the expression inside is defined.$reflect(<identifier>)returns a struct containing information about the identifier, often including the following properties:.size: the size of the value in bytes, the stdlib provides the@sizeof(x)macro as a shorthand for$reflect(x).size..alignment: the alignment of the value in bytes, the stdlib provides@alignof(x)as a shorthand..qname: the qualified name of the identifier, e.gstd::io::printf. The stdlib provides@qnameof(x)as a shorthand..name: the base name of the identifier, e.g.printf. The stdlib provides@nameof(x)as a shorthand.
$Typeof(<expr>)returns the type of the expression.$stringify(<expr>)returns the expression as a string.<type>::sizereturns the size of a type.<type>::alignreturns the alignment of a type.<type>::namereturn the name of a type.
See https://c3-lang.org/generic-programming/reflection/ for the full details.