const指向void的目的是什么

pic*_*c11 2 c c++ pthreads

你觉得奇怪的是pthread_setspecific需要const void指针但pthread_getspecific返回非const void指针吗?

void *pthread_getspecific(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void *value);
Run Code Online (Sandbox Code Playgroud)

链接.

Seb*_*edl 10

嗯,只是另一个不安全的C接口.但事实上,创建一个const-safe版本是不可能的.如果两个函数都是一致的,那么任何想要存储指针的人都const必须const在存储指针时抛弃,或者想要存储指针到非的人const必须const在检索指针时抛弃.它的方式,它不安全,但至少它不会强迫你使用强制转换混乱代码.