void[] vs ubyte[] - differences?
H. S. Teoh
hsteoh at qfbox.info
Wed Jul 16 14:46:45 UTC 2025
On Wed, Jul 16, 2025 at 01:29:01PM +0000, z via Digitalmars-d-learn wrote:
[...]
> 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...
Probably an oversight.
> 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.
[...]
One important difference between void[] and ubyte[] is that void[] may
contain GC-scannable pointers, whereas ubyte[] is assumed to be pure
data. This may be important if you're storing live pointers in a
buffer; if the buffer was allocated as a ubyte[], the GC might not scan
it for pointers and may incorrectly collect live objects. (Though I'm
not 100% sure the current GC implementation actually does this.)
Also, void means "no type", which is completely different from "ubyte",
which means an unsigned 8-bit integer. Some introspection operations
like is(...) expressions return void when given an invalid expression,
whereas returning ubyte means the expression evaluates to an 8-bit
unsigned byte type.
T
--
What's a "hot crossed bun"? An angry rabbit.
More information about the Digitalmars-d-learn
mailing list