Skip to content

Commit 289f9f3

Browse files
authored
[spec/type] Add docs for void type (#4261)
Fixes #4260.
1 parent 9bf7ec2 commit 289f9f3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

spec/arrays.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,8 @@ writefln("the string is '%s'", str);
14071407

14081408
$(H3 $(LNAME2 void_arrays, Void Arrays))
14091409

1410-
$(P There are special types of array with `void` element type which can hold
1411-
arrays of any kind. Void arrays are used for
1410+
$(P There are special types of array with a $(DDSUBLINK spec/type, void, `void`)
1411+
element type which can hold arrays of any kind. Void arrays are used for
14121412
low-level operations where some kind of array data is being handled, but
14131413
the exact type of the array elements are unimportant. The $(D .length) of a
14141414
void array is the length of the data in bytes, rather than the number of

spec/type.dd

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $(H2 $(LEGACY_LNAME2 Basic Data Types, basic-data-types, Basic Data Types))
9797

9898
$(TABLE_3COLS Basic Data Types,
9999
$(THEAD Keyword, Default Initializer ($(D .init)), Description)
100-
$(TROW $(D void), no default initializer, `void` has no value)
100+
$(TROW $(RELATIVE_LINK2 void, $(D void)), no default initializer, `void` has no value)
101101
$(TROW $(RELATIVE_LINK2 bool, $(D bool)), $(D false), boolean value)
102102
$(TROW $(D byte), $(D 0), signed 8 bits)
103103
$(TROW $(D ubyte), $(D 0u), unsigned 8 bits)
@@ -577,6 +577,23 @@ $(H3 $(LNAME2 vrp, Value Range Propagation))
577577
* See also: $(LINK https://en.wikipedia.org/wiki/Value_range_analysis).
578578

579579

580+
$(H2 $(LNAME2 void, $(D void)))
581+
582+
$(P A `void` value cannot be accessed directly. The `void` type is notably used for:)
583+
584+
* The return type of a function that doesn't have a result.
585+
* The base type for an untyped pointer -
586+
see $(RELATIVE_LINK2 pointer-conversions, Pointer Conversions).
587+
* $(DDSUBLINK spec/arrays, void_arrays, Void arrays).
588+
* $(DDSUBLINK spec/expression, cast_void, Ignoring a value) by casting to `void`.
589+
590+
$(P `void.sizeof` is 1 (not 0).)
591+
592+
$(RATIONALE The size must be 1 to make `void*` arithmetic work like it does in C.
593+
It also makes the length of a void array equivalent to the number of
594+
bytes in the array.)
595+
596+
580597
$(H2 $(LNAME2 bool, $(D bool)))
581598

582599
$(P The bool type is a byte-size type that can only hold the value `true` or

0 commit comments

Comments
 (0)