Alex Volkov wrote:
You are confusing
Heh, It won’t be the first or even the last time…
‘forward declaration’ with a ‘conflicting declaration’ (or
union declaration with type declaration).
Here ‘union Foo;’ is indeed a forward declaration of a union tagged ‘Foo’.
However, it is not a declaration of a type named ‘Foo’.
Agreed.
Such forward declare would be
typedef union Blah Foo;
so that later you could define ‘union Blah {};’
Nope. That won’t work for the case Blah = SDL_Event,
because SDL_Event is a typedefed type and not a tag.
My patch just adds a tag with the same name (SDL_Event)
so I can use the method you described…
And this would be a type named ‘Foo’ that is defined by an unnamed union.
Yes.
The reason you may get a different behavior in C++ is because C++ allows to
declare and define full struct/union/class types without a typedef. And
these types can be referred to without their struct/union/class qualifiers.
Yes! However it is not possible to forward declare a typedefed type without a tag
As applied to SDL code in question, I do not see a problem.
Alex, I don’t see how it is possible for me to do the following:
In a header .h file declare a class that uses SDL_Event * (pointer)
without including the <SDL/SDL_events.h> include file. I want to actually
include the <SDL/SDL_events.h> header later in the .cpp implementation file
One other reason for patch inclusion is that is the norm for other
SDL structs. Consider all the SDL_*Event structures. e.g from SDL cvs…
/* Mouse button event structure /
typedef struct SDL_MouseButtonEvent {
Uint8 type; / SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP /
Uint8 which; / The mouse device index /
Uint8 button; / The mouse button index /
Uint8 state; / SDL_PRESSED or SDL_RELEASED /
Uint16 x, y; / The X/Y coordinates of the mouse at press time */
} SDL_MouseButtonEvent;
Here both the type and the tag have the same name SDL_MouseButtonEvent. Why not
also the SDL_Event union? It would be uniform and consistent and forward declarable,
and world peace may soon follow…
.bill