void[] vs ubyte[] - differences?

z z at z.com
Wed Jul 16 13:29:01 UTC 2025


```D
import std;

void main()
{
     void[] a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0x12345678];
     void[] b = cast(ubyte[])[0, 1, 2, 3, 4, 5, 6, 7, 8];
     ubyte[] c = cast(ubyte[])(cast(void[])[0, 1, 2, 3, 4, 5, 6, 
7, 8,0x12345678]);
     ubyte[] d = [0, 1, 2, 3, 4, 5, 6, 7, 8];
     void[] e = cast(ubyte[])a;// same result as a
     void[] f = cast(void[]) a;// same result as a
     writeln(a);
     writeln(b);
     writeln(c);
     writeln(d);
     writeln(e);
     writeln(f);
     writeln(void.sizeof);
}

```
```
[0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 
0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 120, 86, 52, 18]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
[0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 
0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 120, 86, 52, 18]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
[0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 
0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 120, 86, 52, 18]
[0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 
0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 120, 86, 52, 18]
1
//it also appears to expose the platform's endianness
```
I also see this in the language documentation :
```
A void array cannot be indexed.
```
But i can slice it just fine in DMD 2.111...
Is this by design or is there a hole in the language 
specification? By extension what the differences between `void`, 
`ubyte`, `void[]`, `ubyte[]` really? The language documentation 
doesn't appear to be explaining everything.
Thanks in advance


More information about the Digitalmars-d-learn mailing list