There is this answer on another question about the use of cudaMalloc((void**)&device_array, num_bytes)
, which uses void**
as output argument instead of passing a void*
as return value like the standard malloc
.
It criticizes NVIDIA's API and states :
Casting, as in (void**)&device_array, is invalid C and results in undefined behavior.
and has been upvoted several times (8 as of now), so I assume there is some truth in it.
I don't understand what's wrong with casting there.
- What is invalid C here?
- In what case would this lead to undefined behavior?
All I know is that it compiles without warning and runs with the intended behavior for me. But I am not knowledgeable with C up to standard specification level.