@@ -1281,43 +1281,55 @@ writefln("the string is '%s'", str);
12811281
12821282$(H3 $(LNAME2 void_arrays, Void Arrays))
12831283
1284- $(P There is a special type of array which acts as a wildcard that can hold
1285- arrays of any kind, declared as $(D void[]) . Void arrays are used for
1284+ $(P There are special types of array with `void` element type which can hold
1285+ arrays of any kind. Void arrays are used for
12861286 low-level operations where some kind of array data is being handled, but
12871287 the exact type of the array elements are unimportant. The $(D .length) of a
12881288 void array is the length of the data in bytes, rather than the number of
1289- elements in its original type. Array indices in indexing and slicing
1289+ elements in its original type. Array indices in slicing
12901290 operations are interpreted as byte indices.)
12911291
1292- $(P Arrays of any type can be implicitly converted to a void array; the
1292+ $(P Arrays of any type can be implicitly converted to a (tail qualified) void array - the
12931293 compiler inserts the appropriate calculations so that the $(D .length) of
12941294 the resulting array's size is in bytes rather than number of elements. Void
1295- arrays cannot be converted back to the original type without using a cast,
1295+ arrays cannot be converted back to the original type without using an
1296+ $(DDSUBLINK spec/expression, cast_array, array cast),
12961297 and it is an error to convert to an array type whose element size does not
12971298 evenly divide the length of the void array.)
12981299
1299- $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1300+ $(SPEC_RUNNABLE_EXAMPLE_RUN
13001301---------
13011302void main()
13021303{
13031304 int[] data1 = [1,2,3];
1304- long[] data2;
13051305
13061306 void[] arr = data1; // OK, int[] implicit converts to void[].
13071307 assert(data1.length == 3);
13081308 assert(arr.length == 12); // length is implicitly converted to bytes.
13091309
1310- //data1 = arr; // Illegal: void[] does not implicitly
1310+ arr[0..4] = [5]; // Assign first 4 bytes to 1 int element
1311+ assert(data1 == [5,2,3]);
1312+
1313+ //data1 = arr; // Error: void[] does not implicitly
13111314 // convert to int[].
1312- int[] data3 = cast(int[]) arr; // OK, can convert with explicit cast.
1313- data2 = cast(long[]) arr; // Runtime error: long.sizeof == 8, which
1315+ int[] data2 = cast(int[]) arr; // OK, can convert with explicit cast.
1316+ assert(data2 is data1);
1317+ }
1318+ ---------
1319+ )
1320+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1321+ ---------
1322+ void main()
1323+ {
1324+ void[] arr = new void[12];
1325+ long[] bad = cast(long[]) arr; // Runtime error: long.sizeof == 8, which
13141326 // does not divide arr.length, which is 12
13151327 // bytes.
13161328}
13171329---------
13181330)
13191331
1320- $(P Void arrays can also be static if their length is known at
1332+ $(P Void arrays can be static arrays if their length is known at
13211333 compile-time. The length is specified in bytes:)
13221334
13231335$(SPEC_RUNNABLE_EXAMPLE_COMPILE
0 commit comments