C语言编译报错:incompatible pointer type [-Wincompatible-pointer-types](传参类型不匹配)

Posted Dontla

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言编译报错:incompatible pointer type [-Wincompatible-pointer-types](传参类型不匹配)相关的知识,希望对你有一定的参考价值。

代码:

  //arnold add 20211213
  size_t save_video_box_buffer_size = 1920*1080*3/2;
  char* save_video_box_buffer = (char*)malloc(save_video_box_buffer_size); //开辟一块内存用来存储即将做编码推流的buffer(这先不用队列,看看写视频的速度怎么样先,不行再用队列)
  pthread_t main_stream_thread;	//
  //pthread_create(&main_stream_thread, NULL, MainStream, NULL); 	//origin
  pthread_create(&main_stream_thread, NULL, MainStream, save_video_box_buffer);

警告:

ky_ai_camera_engine_origin.c:1519:45: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [-Wincompatible-pointer-types]
   pthread_create(&main_stream_thread, NULL, MainStream, save_video_box_buffer);
                                             ^~~~~~~~~~
In file included from /home/yg/rv/sdk/rv1.8/rv1126_rv1109/buildroot/output/rockchip_rv1126_rv1109/build/ky_ai_camera_engine_origin/src/ky_ai_camera_engine_origin.c:7:
/home/yg/rv/sdk/rv1.8/rv1126_rv1109/buildroot/output/rockchip_rv1126_rv1109/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include/pthread.h:236:15: note: expected ‘void * (*)(void *)’ but argument is of type ‘void * (*)(char *)’
       void *(*__start_routine) (void *),
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

原因是pthread_create()传参类型不一致!传的是void*,需要的是char*


可以统统都改成void*,包括malloc


以上是关于C语言编译报错:incompatible pointer type [-Wincompatible-pointer-types](传参类型不匹配)的主要内容,如果未能解决你的问题,请参考以下文章

错误记录Android Studio 编译报错 ( Module was compiled with an incompatible version of Kotlin. ) 2

错误记录Android Studio 编译报错 ( Module was compiled with an incompatible version of Kotlin. ) 2

错误记录Android Studio 编译报错 ( Deprecated Gradle features were used in this build, making it incompat )

is incompatible with i386:x86-64 output报错

incompatible target

报错 maun.dylib (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))))