The solution is not to use void* unless you really, really have to. The places where a void pointer is actually required are very small: parameters to thread functions, and a handful of others places where you need to pass implementation-specific data through a generic function. In every case, the code that accepts the void* parameter should only accept one data type passed via the void pointer, and the type should be documented in comments and slavishly obeyed by all callers.

Answer from JSBีฑีธีฃีน on Stack Overflow
๐ŸŒ
Learn C++
learncpp.com โ€บ cpp-tutorial โ€บ void-pointers
19.5 โ€” Void pointers โ€“ Learn C++
July 19, 2007 - The void pointer, also known as the generic pointer, is a special type of pointer that can be pointed at objects of any data type!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ cpp-void-pointer
void Pointer in C++ - GeeksforGeeks
June 18, 2026 - A void pointer (void*) is a special type of pointer that can store the address of any data type. Since it is not associated with a specific type, it is also known as a generic pointer.
๐ŸŒ
Codeforwin
codeforwin.org โ€บ home โ€บ void pointer or generic pointer in c โ€“ use and arithmetic
void pointer or generic pointer in C - use and arithmetic - Codeforwin
July 20, 2025 - A void pointer is a special pointer that can point to object of any type. A void pointer is typeless pointer also known as generic pointer.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ void-pointer-c-cpp
void Pointer in C - GeeksforGeeks
A void pointer in C is a special type of pointer that can store the address of any data type. Since it does not have an associated data type, it is often referred to as a generic pointer.
Published: July 4, 2026
Top answer
1 of 6
12

The solution is not to use void* unless you really, really have to. The places where a void pointer is actually required are very small: parameters to thread functions, and a handful of others places where you need to pass implementation-specific data through a generic function. In every case, the code that accepts the void* parameter should only accept one data type passed via the void pointer, and the type should be documented in comments and slavishly obeyed by all callers.

2 of 6
5

This might help:

comp.lang.c FAQ list ยท Question 4.9

Q: Suppose I want to write a function that takes a generic pointer as an argument and I want to simulate passing it by reference. Can I give the formal parameter type void **, and do something like this?

void f(void **);
double *dp;
f((void **)&dp);

A: Not portably. Code like this may work and is sometimes recommended, but it relies on all pointer types having the same internal representation (which is common, but not universal; see question 5.17).

There is no generic pointer-to-pointer type in C. void * acts as a generic pointer only because conversions (if necessary) are applied automatically when other pointer types are assigned to and from void * 's; these conversions cannot be performed if an attempt is made to indirect upon a void ** value which points at a pointer type other than void *. When you make use of a void ** pointer value (for instance, when you use the * operator to access the void * value to which the void ** points), the compiler has no way of knowing whether that void * value was once converted from some other pointer type. It must assume that it is nothing more than a void *; it cannot perform any implicit conversions.

In other words, any void ** value you play with must be the address of an actual void * value somewhere; casts like (void **)&dp, though they may shut the compiler up, are nonportable (and may not even do what you want; see also question 13.9). If the pointer that the void ** points to is not a void *, and if it has a different size or representation than a void *, then the compiler isn't going to be able to access it correctly.

To make the code fragment above work, you'd have to use an intermediate void * variable:

double *dp;
void *vp = dp;
f(&vp);
dp = vp;

The assignments to and from vp give the compiler the opportunity to perform any conversions, if necessary.

Again, the discussion so far assumes that different pointer types might have different sizes or representations, which is rare today, but not unheard of. To appreciate the problem with void ** more clearly, compare the situation to an analogous one involving, say, types int and double, which probably have different sizes and certainly have different representations. If we have a function

void incme(double *p)
{
    *p += 1;
}

then we can do something like

int i = 1;
double d = i;
incme(&d);
i = d;

and i will be incremented by 1. (This is analogous to the correct void ** code involving the auxiliary vp.) If, on the other hand, we were to attempt something like

int i = 1;
incme((double *)&i);    /* WRONG */

(this code is analogous to the fragment in the question), it would be highly unlikely to work.

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_void_pointer.htm
void Pointer in C
A void pointer in C is a type of pointer that is not associated with any data type. A void pointer can hold an address of any type and can be typecasted to any type. They are also called general-purpose or generic pointers.
๐ŸŒ
Programiz
programiz.com โ€บ cpp-programming โ€บ pointer-void
C++ Pointer to void (With Examples)
July 16, 2020 - In this tutorial, we will learn about void pointers and how to use them with the help of examples. The void pointer is a generic pointer that is used when we don't know the data type of the variable that the pointer points to.
๐ŸŒ
Medium
medium.com โ€บ @ayushkapri.richard โ€บ generic-pointers-void-pointers-in-c-c-8541d51bea3e
Generic Pointers (Void Pointers) in C / C++. | by Ayush Kapri | Medium
May 4, 2024 - Generic Pointers (Void Pointers) in C / C++. A void pointer (void *) is a special type of pointer in C and C++ that is used to point to data of unspecified type. It is often used where the type of โ€ฆ
Find elsewhere
๐ŸŒ
Hellocpp
hellocpp.dev โ€บ lesson โ€บ generic-pointer-type
Generic Pointer Type | Advanced C++ Programming | HelloC++
February 7, 2026 - A void pointer is a special type ... cast it to the appropriate type. The void pointer (also called a generic pointer) is a special pointer type that can point to objects of any data type....
๐ŸŒ
Sankalandtech
sankalandtech.com โ€บ Tutorials โ€บ C โ€บ void-pointer-c.html
void Pointers in C programming.
In C programming, a void pointer is declared using the "voidโ€ keyword followed by an asterisk (*) and pointer variable name. This declares a void pointer named ` ptr-name ` that is used point to any data type. void pointer is a generic type of pointer is used to store the address of any data type.
๐ŸŒ
Dot Net Tutorials
dotnettutorials.net โ€บ home โ€บ void pointer in c
Void Pointer in C Language with Examples - Dot Net Tutorials
November 17, 2023 - That means, instead of constructing ... variable properly, i.e., void pointer. As the void pointer can access and manipulate any kind of data variables, it is also called a Generic Pointer....
๐ŸŒ
CSE Department
cse.poriyaan.in โ€บ topic โ€บ generic-pointers-50376
Generic Pointers - with Example C Programs - CSE Department
A generic pointer is a pointer variable that has void as its data type. The void pointer, or the generic pointer, is a special type of pointer that ca
๐ŸŒ
Nerdsdostuff
nerdsdostuff.com โ€บ c_programming โ€บ void-pointer-in-c
Void Pointer in C - Nerds Do Stuff
May 31, 2026 - It is declared using void * and is often called a generic pointer because it is not tied to a specific type such as int *, char *, or float *.
๐ŸŒ
Surakuacademy
surakuacademy.com โ€บ blog โ€บ void-pointer-in-c-language
Magic of void pointer | Void pointer in detail | Suraku Academy
August 1, 2025 - A void pointer is one of the most flexible pointer types in C because it can store the address of variables belonging to any data type. This flexibility makes it extremely useful for generic programming and dynamic memory allocation.
๐ŸŒ
Aticleworld
aticleworld.com โ€บ home โ€บ void pointer in c/c++, you should know
void pointer in C/C++, you should know - Aticleworld
April 14, 2020 - A void pointer in c is called a generic pointer, it has no associated data type. It can store the address of any type of object and it can be type-casted to any type. According to C standard, the pointer to void shall have the same representation ...
๐ŸŒ
Embeddedpathashala
embeddedpathashala.com โ€บ home โ€บ what is void pointer in c explained- free online c programming course
What is void Pointer in C Explained- Free Online C Programming Course - embeddedpathashala.com
1 week ago - In this lecture of our free C programming course we meet the void pointer in C, also called the generic pointer. Every other pointer type you have used so far is strict: an int * may only hold the address of an int.
๐ŸŒ
W3office
w3office.com โ€บ home โ€บ c tutorial โ€บ ๐Ÿ“ c pointers โ€บ ๐Ÿ”ณ c void pointer
Learn C void Pointer โ€“ Syntax, Casting, and Best Practices
May 18, 2025 - รฐยŸย”ยณ C void Pointer โ€“ The Generic Pointer in C Introduction โ€“ What Is a void Pointer in C? In C programming, a void pointer (also called a generic pointer) is a special type of pointer that can point to any data type. It is declared as void * and provides flexibility in memory management, ...
๐ŸŒ
BYJUS
byjus.com โ€บ gate โ€บ void-pointer-in-c
Void Pointer in C
August 1, 2022 - The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means that it points to the address of variables.