diff --git a/doc/langref.html.in b/doc/langref.html.in index 7c1f9b53d9e6..f1ae2bafaa44 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -1651,7 +1651,7 @@ fn foo(bytes: []u8) u32 {
@ptrCast(*u32, f32(12.34)).*
Instead, use {#link|@bitCast#}:
@bitCast(u32, f32(12.34))
- As an added benefit, the @bitcast
version works at compile-time.
As an added benefit, the @bitCast
version works at compile-time.
TODO: ptrcast builtin
TODO: explain number literals vs concrete types
{#header_close#} + {#header_open|void#} -TODO: assigning void has no codegen
-TODO: hashmap with void becomes a set
-TODO: difference between c_void and void
-TODO: void is the default return value of functions
-TODO: functions require assigning the return value
+
+ void
represents a type that has no value. Code that makes use of void values is
+ not included in the final generated code:
+
When this turns into LLVM IR, there is no code generated in the body of entry
,
+ even in debug mode. For example, on x86_64:
0000000000000010 <entry>:
+ 10: 55 push %rbp
+ 11: 48 89 e5 mov %rsp,%rbp
+ 14: 5d pop %rbp
+ 15: c3 retq
+ These assembly instructions do not have any code associated with the void values - + they only perform the function call prologue and epilog.
+
+ void
can be useful for instantiating generic types. For example, given a
+ Map(Key, Value)
, one can pass void
for the Value
+ type to make it into a Set
:
+
Note that this is different than using a dummy value for the hash map value.
+ By using void
as the type of the value, the hash map entry type has no value field, and
+ thus the hash map takes up less space. Further, all the code that deals with storing and loading the
+ value is deleted, as seen above.
+
+ void
is distinct from c_void
, which is defined like this:
+ pub const c_void = @OpaqueType();
.
+ void
has a known size of 0 bytes, and c_void
has an unknown, but non-zero, size.
+
+ Expressions of type void
are the only ones whose value can be ignored. For example:
+
However, if the expression has type void
:
TODO: example of this referring to Self struct
TODO: example of this referring to recursion function