I believe the following code is well-defined according to the C standard:
void f(void **);
void *p;
f((void **)&p);
But what if p
isn’t a pointer to void, say:
void f(void **);
double *p;
f((void **)&p);
According to the C FAQ, it is not portable. However, it does not cause my compiler to emit any warnings, and searching well known C codebases yields many instances of such non-void *
-casts, for example Linux, CPython, and COM all do it. The answers of the most closely related SO question that I could find make no mention of this being strange or nonstandard. So, is this usage of void **
really non-portable? And if so why does it seem to be common practice?
emron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.