void (NOTE: not void *), is a type with a size of zero, that other types cannot cast to. There are no values of the type void. A variable can be declared a type of void
, but it will have a size of 0.
variable: void;
print("%\n", variable); // prints out 'void'
A function that returns void can return a void variable. This can be useful when working with polymorphic structs/functions, and you want to return an empty void from the function.
function :: () -> void {
variable: void;
return variable;
}
void
can also be used as a polymorphic type in e.g. f :: ($T: Type) -> T { x: T; return x; }
as T
: f(void)
void as a struct member
void
can be used as struct members. This allows you to put notes on struct members that do not take up space, or serve as markers for a #place
directive.
Object :: struct {
member: void; @notes
#place member;
x: float;
#place member;
y: float;
#place member;
z: float;
}