When is casting void pointer needed in C?

后端 未结 5 1565
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 13:56

I\'ve been looking at Advanced Linux Programming by Mitchell, Oldham and Samuel. I\'ve seen in the section on pthreads something about void pointers and casting tha

5条回答
  •  执念已碎
    2020-12-05 14:45

    In C, casting to void* from any pointer type and vice-versa is done implicitly. There's no need for the cast in the second example.

    (Note that in C++ casting any pointer to void* is also done implicitly (except for function pointers and function-member / method pointers which cannot be cast to void*), but casting back requires an explicit cast.)

提交回复
热议问题