Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Emscripten] testcontroller error and checkkeys warning #11445

Open
Sackzement opened this issue Nov 11, 2024 · 2 comments
Open

[Emscripten] testcontroller error and checkkeys warning #11445

Sackzement opened this issue Nov 11, 2024 · 2 comments
Milestone

Comments

@Sackzement
Copy link
Contributor

I tried compiling SDL with Emscripten following the README-emscripten.md documentation.

Building SDL and examples work.

But building the tests fails:

[ 50%] Building C object test/CMakeFiles/checkkeys.dir/checkkeys.c.o
/path/to/SDL-git/test/checkkeys.c:237:17: warning: incompatible pointer types initializing 'const bool *' with an expression of type 'const unsigned char *' [-Wincompatible-pointer-types]
  237 |     const bool *keystate = SDL_GetKeyboardState(&max_keys);
      |                 ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 75%] Building C object test/CMakeFiles/testcontroller.dir/testcontroller.c.o
/path/to/SDL-git/test/testcontroller.c:1175:17: error: incompatible function pointer types assigning to 'unsigned char (*)(void *, Uint16, Uint16)' (aka 'unsigned char (*)(void *, unsigned short, unsigned short)') from 'bool (void *, Uint16, Uint16)' (aka 'bool (void *, unsigned short, unsigned short)') [-Wincompatible-function-pointer-types]
 1175 |     desc.Rumble = VirtualGamepadRumble;
      |                 ^ ~~~~~~~~~~~~~~~~~~~~
/path/to/SDL-git/test/testcontroller.c:1176:25: error: incompatible function pointer types assigning to 'unsigned char (*)(void *, Uint16, Uint16)' (aka 'unsigned char (*)(void *, unsigned short, unsigned short)') from 'bool (void *, Uint16, Uint16)' (aka 'bool (void *, unsigned short, unsigned short)') [-Wincompatible-function-pointer-types]
 1176 |     desc.RumbleTriggers = VirtualGamepadRumbleTriggers;
      |                         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/to/SDL-git/test/testcontroller.c:1177:17: error: incompatible function pointer types assigning to 'unsigned char (*)(void *, Uint8, Uint8, Uint8)' (aka 'unsigned char (*)(void *, unsigned char, unsigned char, unsigned char)') from 'bool (void *, Uint8, Uint8, Uint8)' (aka 'bool (void *, unsigned char, unsigned char, unsigned char)') [-Wincompatible-function-pointer-types]
 1177 |     desc.SetLED = VirtualGamepadSetLED;
      |                 ^ ~~~~~~~~~~~~~~~~~~~~

Because of the bool/unsigned char mismatch, my guess is that SDL was built with C, but the tests are built with C++.

@Sackzement
Copy link
Contributor Author

Explicitly casting bool to unsigned char and unsigned char to bool gets rid of the errors and warning.
But I don't think it's a good fix, since compilers could build SDL with a bool extension and the problem would appear again.

diff --git a/test/checkkeys.c b/test/checkkeys.c
index c81f9aa83..98f19e90b 100644
--- a/test/checkkeys.c
+++ b/test/checkkeys.c
@@ -234,7 +234,7 @@ static void PrintText(const char *eventtype, const char *text)
 static void CountKeysDown(void)
 {
     int i, count = 0, max_keys = 0;
-    const bool *keystate = SDL_GetKeyboardState(&max_keys);
+    const bool *keystate = (const bool *)SDL_GetKeyboardState(&max_keys);
 
     for (i = 0; i < max_keys; ++i) {
         if (keystate[i]) {
diff --git a/test/testcontroller.c b/test/testcontroller.c
index 6b5874156..48ad292f1 100644
--- a/test/testcontroller.c
+++ b/test/testcontroller.c
@@ -1172,9 +1172,9 @@ static void OpenVirtualGamepad(void)
     desc.nsensors = 1;
     desc.sensors = &virtual_sensor;
     desc.SetPlayerIndex = VirtualGamepadSetPlayerIndex;
-    desc.Rumble = VirtualGamepadRumble;
-    desc.RumbleTriggers = VirtualGamepadRumbleTriggers;
-    desc.SetLED = VirtualGamepadSetLED;
+    desc.Rumble = (unsigned char (*)(void *, Uint16, Uint16))VirtualGamepadRumble;
+    desc.RumbleTriggers = (unsigned char (*)(void *, Uint16, Uint16))VirtualGamepadRumbleTriggers;
+    desc.SetLED = (unsigned char (*)(void *, Uint8, Uint8, Uint8))VirtualGamepadSetLED;
 
     virtual_id = SDL_AttachVirtualJoystick(&desc);
     if (virtual_id == 0) {

@Sackzement
Copy link
Contributor Author

Because of the bool/unsigned char mismatch, my guess is that SDL was built with C, but the tests are built with C++.

It isn't a C/C++ mismatch, but rather a mismatch with the C standards, which are used to build SDL and the tests.

gcc/clang SDL:
__STDC__         = 1
__STDC_VERSION__ = 201710L
__cplusplus      = not defined
(bool)0.5f       = 1
-> -std=gnu17 (default) ?

gcc/clang Tests:
__STDC__         = 1
__STDC_VERSION__ = not defined
__cplusplus      = not defined
(bool)0.5f       = 0
-> -std=c89 ?

emcc SDL:
__STDC__         = 1
__STDC_VERSION__ = 201710L
__cplusplus      = not defined
(bool)0.5f       = 1
-> -std=gnu17 (default) ?

emcc Tests:
__STDC__         = 1
__STDC_VERSION__ = not defined
__cplusplus      = not defined
(bool)0.5f       = 1
-> -std=gnu89 ?

@slouken slouken added this to the 3.2.0 milestone Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants