Re: [AD] version check in allegro_init

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Peter Wang a écrit :
> Evert Glebbeek wrote:
> >Doing this using install_allegro() makes the most sense, but we can't add
> >arguments to the function because it's part of the public API.
>
> Well, we could bend the rules a little.  As Elias suggested we could
> change install_allegro into a macro.  For the rare cases where people
> take the address of install_allegro, we still define install_allegro as
> a function.  If you call install_allegro and bypass the macro you won't
> get the version check, but that's okay.

Another possible solution that doesn't change the API would be to encode the 
version numbers into the system IDs. So, instead of:

    #define SYSTEM_AUTODETECT  0
    #define SYSTEM_NONE        AL_ID('N','O','N','E')
    #define SYSTEM_BEOS        AL_ID('B','S','Y','S')
    ...

We could have something like that:

    #define AL_SYSTEM_ID(x) \
        (((x)<<24) | (ALLEGRO_VERSION<<16) | \
        (ALLEGRO_SUB_VERSION<<8) | (ALLEGRO_WIP_VERSION))

    #define SYSTEM_AUTODETECT  AL_SYSTEM_ID(0)
    #define SYSTEM_NONE        AL_SYSTEM_ID(1)
    #define SYSTEM_BEOS        AL_SYSTEM_ID(2)
    ...

Then install_allegro can extract the version numbers from the system ID, and 
do the check. We get full compatibility, and the check is always done. This 
is a bit hackish, but IMHO no more than turning install_allegro into a macro.

-- 
Julien Cugnière




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/