/* Test GCC 8.1 -Wcast-function-type for https://bugs.python.org/issue33015 * * Compiled on Linux with: * gcc x.c -o x -Wall -Wextra -lpthread * * Workaround the cast: * gcc x.c -o x -Wall -Wextra -lpthread -D UGLY_CAST */ #include #include /* No result value */ typedef void (*python_callback) (void *); /* Result type: "void*" (untyped pointer) */ typedef void* (*pthread_callback) (void *); void mythread(void * arg __attribute__((unused))) { printf("hello from thread!\n"); pthread_exit(0); } int test_cast(python_callback func) { pthread_t thread; int res; void *arg = NULL; void *retval = NULL; #ifdef UGLY_CAST pthread_callback func2 = (pthread_callback)(void *)func; #else pthread_callback func2 = (pthread_callback)func; #endif res = pthread_create(&thread, NULL, func2, arg); printf("pthread_create -> %i\n", res); if (res != 0) { printf("pthread_create failed\n"); return 1; } res = pthread_join(thread, retval); printf("pthread_join -> %i\n", res); return (res == 0); } int main(void) { return test_cast(mythread); }

AltStyle によって変換されたページ (->オリジナル) /