How to check if void pointer points to NULL?

c, pointers, void-pointers

Solution

I'd simply write `if (!ptr)`.

`NULL` is basically just `0` and `!0` is true.

Problem

So if you do: ``` void *ptr = NULL; ``` What is the best way to check if that void pointer is NULL? My workaround for now is this: ``` if (*(void**)ptr == NULL) ... ``` But this doesn't seem like the best way, as I'm implicitly assuming ptr is of type void** (which it isn't).

Original source

Related problems