Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is void[]?

Tags:

d

I've seen the type void[] used in a few places in the D documentation and function signatures. What does it mean?

I've searched the array section in the documentation as well as Google, but didn't turn up anything conclusive. All I found is that all arrays are implicitly convertible to the void[] type. Is it just an untyped array?

like image 511
Colonel Thirty Two Avatar asked Dec 09 '14 18:12

Colonel Thirty Two


People also ask

What does void *) mean in C?

void (C++) If a pointer's type is void* , the pointer can point to any variable that's not declared with the const or volatile keyword. A void* pointer can't be dereferenced unless it's cast to another type. A void* pointer can be converted into any other type of data pointer.

What is void variable?

A function that does not return is treated as a function that returns a void value. A non-returning function can be assigned to a variable of type void . Initializing a variable without a specified type with a function that doesn't return will infer the variable type to be void .

Can an array be void?

You can't have a variable of type void (or an array of void ) for the simple reason that there are no values of type void for it to hold.

Can you have an array of void in C?

In C, it is possible to have array of all types except following. 1) void. 2) functions. But we can have array of void pointers and function pointers.


1 Answers

void[] is just an array of anything. in void[] is a convenient signature for a function that just writes bytes to a file or something because it will accept any kind of array - void meaning the type isn't important and in meaning you aren't meaning to modify or store it, thus allowing you to accept const or immutable arrays too.

To use a void[], you must first cast it to something else, typically, ubyte[], so the elements have a concrete size allowing you to index it. void[].length is given as the total number of bytes in the array, so if you are just passing a pointer and length of data to a function (like an operating system level file write, e.g. Linux's write syscall), passing arr.ptr, arr.length will get those bytes written without caring about what they represent.

like image 90
Adam D. Ruppe Avatar answered Nov 02 '22 08:11

Adam D. Ruppe