Note this answer assumes dynamic type conversion as definition
void* is not a dynamic type, it is a pointer without a type, that doesn't make it a dynamic type because it's type does not automagically adapt to the situations as in Javascript.
For example such code wouldn't work at all:
void* test = malloc(20);
test[0] = 'E'; /* dereferencing void pointer */
puts(test);
Void pointers has to be casted by the programmer and in a sense that what would "dynamic" correspond to is not dynamic.
Some of C Compilers may cast void into other types automatically at compile time but that wouldn't make it dynamic.
Technically speaking similar thing can be done with char* too and you can convert it into a int and that wouldn't make it dynamic.
char* e = malloc(sizeof(int));
memset(e, 0, sizeof(int));
int coolint = *(int*)(e);
printf("%d", coolint);
It's better to think void* like an any type, anything stored in your computer's memory is represented by bytes and by themselves they do not correspond to any type they are just numbers make up the data.
Main usage area of void* in C is to emulate polymorphism.
void *
can be used for a technique called "type erasure" where a portion of the code has no knowledge of the type of the object (it obviously can't make use of the object as it doesn't know what type it is).QVariant
- "...The QVariant class acts like a union for the most common Qt data types...." - it'sunion
wrapper for a few fixed Qt types. So not dynamic at all. The typesQVariant
can hold are fixed: (a) by design of Qt and (b) at compile time. See alsostd::variant
. ps the QVariant link in the question is broken.