SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL2: SDL_mutex.h violates C90

Open Wohlstand opened this issue 3 years ago • 1 comments

Recently I met a failure at the SDL_mutex.h when including it in C90-enforced project:

SDL_mutex.h:42:48: error: expected declaration specifiers before ‘/’ token
   42 | #define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x)   // no-op
      |                                                ^

In addition, there is a warning at anonymous variadic macros given:

SDL_mutex.h:57:29: warning: anonymous variadic macros were introduced in C99 [-Wvariadic-macros]
   57 | #define SDL_ACQUIRED_BEFORE(...) \
      |                             ^~~

Wohlstand avatar Dec 18 '22 04:12 Wohlstand

I fixed the C++ comment, but I'm not sure what can be done about the varargs macros, so I'm going to leave that to someone else to look at.

icculus avatar Dec 18 '22 04:12 icculus

Speaking about anonymous variadic macros, maybe just add the ability to hide these macros at all? like:

#ifndef SDL_MUTEX_DISABLE_ANNOTATION_ATTRIBUTE_MACROS

/* ... */

#endif

So, user at the application could specify the SDL_MUTEX_DISABLE_ANNOTATION_ATTRIBUTE_MACROS macro to avoid them at all. It shouldn't affect existing stuff because it will be undefined by default.

What do you think?

Wohlstand avatar May 10 '23 04:05 Wohlstand

Also, maybe make them being single-entry? Because I hadn't found any uses with multiple entries listed...

EDIT: there is only SDL_TRY_ACQUIRE() is being used with two arguments, so, "x, y" for it.

Wohlstand avatar May 10 '23 05:05 Wohlstand

I made an experimental thing just for myself: https://github.com/WohlSoft/AudioCodecs/commit/5e567e26097d2f5a86ba4a0f7ecae70d59805fb0 If seems fine, you can take it into mainstream.

Wohlstand avatar May 10 '23 05:05 Wohlstand

Added, thanks!

slouken avatar May 10 '23 13:05 slouken