SanderMertens / flecs

A fast entity component system (ECS) for C & C++

Home Page:https://www.flecs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiling on windows with gcc -c flecs.c -Wall -Wextra -Werror

KenthJohan opened this issue · comments

$ gcc -c flecs.c -Wall -Wextra -Werror
flecs.c: In function 'win_thread_new':
flecs.c:19186:18: error: cast between incompatible function types from 'ecs_os_thread_callback_t' {aka 'void * (*)(void *)'} to 'DWORD (*)(void *)' {aka 'long unsigned int (*)(void *)'} [-Werror=cast-function-type]
19186 |         NULL, 0, (LPTHREAD_START_ROUTINE)callback, arg, 0, NULL);
      |                  ^
flecs.c: In function 'win_ainc':
flecs.c:19213:33: error: passing argument 1 of '_InterlockedIncrement' from incompatible pointer type [-Werror=incompatible-pointer-types]
19213 |     return InterlockedIncrement(count);
      |                                 ^~~~~
      |                                 |
      |                                 int32_t * {aka int *}
In file included from C:/msys64/mingw64/include/winnt.h:27,
                 from C:/msys64/mingw64/include/minwindef.h:163,
                 from C:/msys64/mingw64/include/windef.h:9,
                 from C:/msys64/mingw64/include/windows.h:69,
                 from C:/msys64/mingw64/include/winsock2.h:23,
                 from flecs.c:19176:
C:/msys64/mingw64/include/psdk_inc/intrin-impl.h:1670:51: note: expected 'volatile long int *' but argument is of type 'int32_t *' {aka 'int *'}
 1670 | __LONG32 _InterlockedIncrement(__LONG32 volatile *Addend) {
      |                                                   ^
flecs.c: In function 'win_adec':
flecs.c:19220:33: error: passing argument 1 of '_InterlockedDecrement' from incompatible pointer type [-Werror=incompatible-pointer-types]
19220 |     return InterlockedDecrement(count);
      |                                 ^~~~~
      |                                 |
      |                                 int32_t * {aka int *}
C:/msys64/mingw64/include/psdk_inc/intrin-impl.h:1681:51: note: expected 'volatile long int *' but argument is of type 'int32_t *' {aka 'int *'}
 1681 | __LONG32 _InterlockedDecrement(__LONG32 volatile *Addend) {
      |                                                   ^
flecs.c: In function 'win_enable_high_timer_resolution':
flecs.c:19357:29: error: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'LONG (*)(ULONG,  BOOLEAN,  ULONG *)' {aka 'long int (*)(long unsigned int,  unsigned char,  long unsigned int *)'} [-Werror=cast-function-type]
19357 |     pNtSetTimerResolution = (LONG(__stdcall*)(ULONG, BOOLEAN, ULONG*))
      |                             ^
flecs.c: At top level:
flecs.c:36297: error: ignoring '#pragma comment ' [-Werror=unknown-pragmas]
36297 | #pragma comment(lib, "Ws2_32.lib")
      |
flecs.c: In function 'http_accept_connections':
flecs.c:37390:22: error: comparison of integer expressions of different signedness: 'int' and 'SOCKET' {aka 'long long unsigned int'} [-Werror=sign-compare]
37390 |     if (SOCKET_ERROR == testsocket && WSANOTINITIALISED == WSAGetLastError()) {
      |                      ^~
cc1.exe: all warnings being treated as errors

if (SOCKET_ERROR == testsocket && WSANOTINITIALISED == WSAGetLastError()) {

Should be INVALID_SOCKET

return InterlockedIncrement(count);

Maybe cast to (__LONG32 volatile *)count

Maybe the rest could be cast to (void*)
(LPTHREAD_START_ROUTINE)(void*)callback

pNtSetTimerResolution = (LONG(__stdcall*)(ULONG, BOOLEAN, ULONG*))(void*)GetProcAddress(hntdll, "NtSetTimerResolution");

commented

I don't think casting the function pointer is a solution. Returning a void* from a LPTHREAD_START_ROUTINE is simply wrong; the return value is an exit code, not a pointer. Even if it doesn't cause corruption due to incompatible types, on 64 bit Windows the exit code of the thread will be missing a lot of bits. Return value of the start routine needs to match what is expected, although I suppose that is made difficult due to the OS agnostic nature of the OS API.

Fixed!