Comments (8)
Feel free to create a PR to fix these. I think you might be able to remove the signal handler casts.
from sdl.
Oh, don't bother fixing -Wunused-parameter. I'm not sure about sign compare. I tend to fix them when they come up, but the fix is usually a cast and it's not always obvious what the correct cast is.
from sdl.
Be careful with casting function pointers, it can lead to problems on some platforms (e.g. WASM). Especially if the function is being called through a pointer with a different signature than it was declared with.
from sdl.
don't bother fixing -Wunused-parameter
In many of the projects I maintain, the build system explicitly turns this one off. It has a poor signal to noise ratio in any API that involves callbacks.
-Wcast-function-type
In places where more force is needed, gcc will let you cast any function pointer to/from a void (*) (void)
without this warning, which makes it into the equivalent of void *
for data pointers:
typedef void (*SigactionFunc) (int, siginfo_t *, void *);
-foo = (SigactionFunc) bar;
+foo = (SigactionFunc) (void (*) (void)) bar;
In GLib-world, this type is typedef'd as GCallback
. In SDL it's the same as __GLXextFuncPtr
and __eglMustCastToProperFunctionPointerType
but it might be worthwhile to have a more self-documenting typedef like
typedef void (*SDLFunction) (void);
...
foo = (SigactionFunc) (SDLFunction) bar;
from sdl.
Be careful with casting function pointers
Yes, this has a warning for a reason. It can be done, but only if there is an out-of-band way to keep track of the function's real type - for example in sigaction()
, the sa_handler
and sa_sigaction
members of struct sigaction
are sometimes the same bytes of memory (via a union), and the out-of-band tracking for which signature is the right one is based on whether sa_flags
contains SA_SIGINFO
.
if the function is being called through a pointer with a different signature than it was declared with
In general this is undefined behaviour, although I think it might be allowed if the signatures only have trivial differences such as adding/removing const.
from sdl.
-Wmissing-field-initializers
This is another warning with a poor signal-to-noise ratio and I'd suggest explicitly turning it off. The effect of a missing field initializer is well-defined in the C standard (pointers become NULL, numbers become zero), and some APIs involve structs that were specifically designed to be partially-initialized like this.
from sdl.
SDL already has SDL_FunctionPointer
, which can probably be used to cast in this case.
from sdl.
I found the flags -Wcast-function-type
and -Wcast-function-type-strict
for clang
.
These weren't automatically enabled with -Wextra
.
These flags detect many many more unregular function casts.
Here are some interesting stats about how many were found in which files:
I separated them into categories.
// signals:
src/events/SDL_quit.c 1 warning generated.
src/core/linux/SDL_evdev_kbd.c 1 warning generated.
// misc:
src/hidapi/SDL_hidapi.c 29 warnings generated.
src/core/linux/SDL_dbus.c 42 warnings generated.
src/storage/steam/SDL_steamstorage.c 9 warnings generated.
// graphics:
src/render/opengl/SDL_render_gl.c 54 warnings generated.
src/render/opengl/SDL_shaders_gl.c 15 warnings generated.
src/render/opengles2/SDL_render_gles2.c 56 warnings generated.
src/render/vulkan/SDL_render_vulkan.c 96 warnings generated.
src/video/SDL_egl.c 29 warnings generated.
src/video/SDL_video.c 9 warnings generated.
src/video/SDL_vulkan_utils.c 8 warnings generated.
src/video/x11/SDL_x11opengl.c 16 warnings generated.
src/video/x11/SDL_x11vulkan.c 10 warnings generated.
src/video/kmsdrm/SDL_kmsdrmvulkan.c 13 warnings generated.
src/video/wayland/SDL_waylandvulkan.c 7 warnings generated.
src/video/offscreen/SDL_offscreenvulkan.c 7 warnings generated.
src/gpu/vulkan/SDL_gpu_vulkan.c 114 warnings generated.
// tests:
src/test/SDL_test_harness.c 1 warning generated.
testffmpeg.c 2 warnings generated.
testffmpeg_vulkan.c 28 warnings generated.
testgl.c 46 warnings generated.
testgles2.c 56 warnings generated.
testgles2_sdf.c 56 warnings generated.
testloadso.c 1 warning generated.
testshader.c 12 warnings generated.
testvulkan.c 44 warnings generated.
from sdl.
Related Issues (20)
- [Feature Request] SDL3 GPU Backend for WebGPU Target HOT 9
- testautomation_surface.c: SDLTest_AssertCheck() is always true HOT 1
- SDL3 SDL_malloc.c #define FORCEINLINE problem HOT 7
- GPU: Functions that may return errors should call SDL_SetError() HOT 5
- SDL_gpu_vulkan.c will always enable validation, not honoring the SDL_HINT_RENDER_VULKAN_DEBUG hint HOT 4
- SDL_WINDOWEVENT_EXPOSED not triggered on sway HOT 3
- Change SDL_GPU_TEXTUREFORMAT_INVALID to SDL_GPU_TEXTUREFORMAT_UNKNOWN = 0? HOT 2
- GPU: Reasonable zero-init defaults
- Can crash if Pipewire hotplug_loop_init() fails HOT 2
- Vcpkg Port Question HOT 3
- blit_testExampleApplicationRender failing on big-endian
- GPU shader format bit flags skip value 1 HOT 1
- Undefined symbols in project after trying to link SDL2 statically HOT 5
- Add new tutorial to sdl2 wiki HOT 1
- Guard against thread creation failure in PULSEAUDIO_DetectDevices HOT 6
- SDL_ShowSimpleMessageBox not working with wayland
- GPU: Remove lock in Vulkan FetchDescriptorSet
- I would love a SDL_GPU_DISABLED if possible, please. HOT 1
- GPU: User Clip Planes? (gl_ClipDistance / SV_ClipDistance)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdl.