So the SDL_Event union looks something like this (using C++ syntax):
union SDL_Event {
uint8_t type;
SDL_CommonEvent common;
SDL_DisplayEvent display;
// ...
};
most C unions I’ve seen instead would have used this approach:
struct SDL_Event {
uint8_t type;
SDL_EventData data;
};
union SDL_EventData {
SDL_CommonEvent common;
SDL_DisplayEvent display;
// ...
};
The second approach saves retyping the type
parameter in every union type.
Why was this done?
One idea coming to mind is the matter of alignment. Having a uint8_t could lead to padding which would interface poorly with languages such as C# where you have to hardcode the member offsets for interfacing with C unions. Although that padding would persist in the union types as well so I don’t think it’s this.
Thanks
Folling