incompatible pointer type in C

后端 未结 3 1241
傲寒
傲寒 2020-12-06 15:27

so I\'m trying to pass a type double * to a function that accepts void ** as one of the parameters. This is the warning that I am getting.

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 15:56

    Even though all other pointer types can be converted to and from void * without loss of information, the same is not true of void ** and other pointer-to-pointer types; if you dereference a void ** pointer, it needs to be pointing at a genuine void * object1.

    In this case, presuming that dequeue() is returning a single pointer value by storing it through the provided pointer, to be formally correct you would need to do:

    int main( void )
    {
        void *p;
        double *target;
    
        success = dequeue(queueIn, &p);
        target = p;
    

    When you write it like this, the conversion from void * to double * is explicit, which allows the compiler to do any magic that's necessary (even though in the overwhelmingly common case, there's no magic at all).


    1. ...or a char *, unsigned char * or signed char * object, because there's a special rule for those.

提交回复
热议问题