Warning: cast to/from pointer from/to integer of different size

前端 未结 4 1198
故里飘歌
故里飘歌 2020-12-14 01:21

I\'m learning Pthreads. My code executes the way I want it to, I\'m able to use it. But it gives me a warning on compilation.

I compile using:

gcc          


        
4条回答
  •  暖寄归人
    2020-12-14 02:04

    A quick hacky fix might just to cast to long instead of int. On a lot of systems, sizeof(long) == sizeof(void *).

    A better idea might be to use intptr_t.

    int threadnumber = (intptr_t) param;
    

    and

    pthread_create(&(tid[i]), &attr, runner, (void *)(intptr_t)i);
    

提交回复
热议问题