Is there a legitimate use for void*?

void* is at least necessary as the result of ::operator new (also every operator new…) and of malloc and as the argument of the placement new operator.

void* can be thought as the common supertype of every pointer type. So it is not exactly meaning pointer to void, but pointer to anything.

BTW, if you wanted to keep some data for several unrelated global variables, you might use some std::map<void*,int> score; then, after having declared global int x; and double y; and std::string s; do score[&x]=1; and score[&y]=2; and score[&z]=3;

memset wants a void* address (the most generic ones)

Also, POSIX systems have dlsym and its return type evidently should be void*

Leave a Comment

tech