Is casting to pointers to pointers to void always safe?

前端 未结 3 665
暗喜
暗喜 2021-01-20 14:31
#include 

void swap(void *v[], int i, int j)
{
    void *tmp;

    tmp = v[i];
    v[i] = v[j];
    v[j] = tmp;
}

int main(void)
{
    char *s[] = {         


        
3条回答
  •  被撕碎了的回忆
    2021-01-20 15:04

    To avoid the warning call the function as follows,

    swap((void *) s, 0, 1);
    

    It is always safe to cast any pointer as a void pointer.

提交回复
热议问题