When you have a void*
, you can implicitly convert it to any pointer type. This only works with a void*
. It doesn't work for a double*
, and it doesn't work for an int
, which would not even be a pointer.
When you add the cast, you expand the set of allowed input types. Suddenly, any pointer is eligible for conversion as is any integral type.
Now, what happens if you cast an int
to myStruct*
? Exactly. Bullshit. You want the compiler to throw an error on this.
Likewise, if you have a pointer, and you convert it implicitly to a void*
, that only works for pointers (and a 0
literal). If you add a cast, you lose the check that the value actually is a pointer. Now the conversion works just as well with a char
as input.
And what happens when you cast a 'a'
to a pointer? Exactly. Bullshit. You want the compiler to throw an error on this.
So, please, don't add unnecessary casts. They invariably broaden the potential for bugs not being caught by the compiler. If you must pass a pointer through a void*
, make sure that that only works with pointers.