cast to pointer from integer of different size, pthread code

前端 未结 3 2113
悲&欢浪女
悲&欢浪女 2020-12-16 19:15

I have this code for matrix multiplication, using pthreads, but I get the error \"cast to pointer from integer of different size\"

I don\'t know what is wrong.I am n

3条回答
  •  时光取名叫无心
    2020-12-16 19:30

    You want to cast integer, short, or char and set a pointer to that value use the reinterpret_cast() call. We used to just (void*) the value and the older compilers were happy, but the new versions, for example g++ 4.8.5, know the value is not the right size for a pointer. reinterpret_cast is just like a cast but it resized it so the compile doesn't complain.

    For example:

    int i = 3;
    pointer void * ptr;
    
    ptr = (void*)i;                    // will generate the warning
    ptr = reinterpret_cast(i);  // No warning is generated
    

    X11 example getting a character out of addr and then setting XTPOINTER to it.

    val = (XTPOINTER)(*(char*)toVal.addr);                   //  warning
    val = reinterpret_cast(*(short*)toVal.addr);  // No warning
    

提交回复
热议问题