libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
430 stars 147 forks source link

Identifier `_Mix_Music` is reserved #605

Open DanRStevens opened 7 months ago

DanRStevens commented 7 months ago

The following type definition uses a reserved identifier _Mix_Music:

typedef struct _Mix_Music Mix_Music;

According to: https://en.cppreference.com/w/cpp/language/identifiers

Identifiers that appear as a token or preprocessing token (i.e., not in user-defined-string-literal like operator ""id)(since C++11) of one of the following forms are reserved:

  • identifiers with a double underscore anywhere;
  • identifiers that begin with an underscore followed by an uppercase letter;
  • in the global namespace, identifiers that begin with an underscore.

Similarly, the GNU documentation states: https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html

In addition to the names documented in this manual, reserved names include all external identifiers (global functions and variables) that begin with an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names.


When compiling code with Clang, the -Wreserved-identifier flag will warn about this name.


I noticed this when attempting to reduce transitive header includes in a project I was working on. I had tried to replace an include for SDL_mixer.h and a forward declare for Mix_Music, which required that I also use the name _Mix_Music. I occasionally compile my project with Clang's -Weverything flag and see what comes up.