incompatible pointer type in C

后端 未结 3 1232
傲寒
傲寒 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:32
    int main( void )
    {
        //  Local Declaration
        double *target;
    
       //   Statement
       success = dequeue(queueIn, (void**)&target);
    }
    

    Use it like this.

    0 讨论(0)
  • 2020-12-06 15:49

    In your prototype declaration , you said second argument as void** ,so you have to type cast double** to void**. Instead of this line success = dequeue(queueIn, &target);.

    Call like this success = dequeue(queueIn,(void**) &target);

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题