Fwd: Re: [AD] New END_OF_MAIN() Proposal

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


--- Chris wrote:
> Evert Glebbeek wrote:
> >>It still involves macro magic and
> >>the 'main' function would still need to have 'int'
> >>specified, but this method would pretty it up a
> little
> >>bit.
> > 
> > 
> > Indeed. I think most users specify int main()
> anyway (as opposed to just 
> > main()). SDL also forces you to declare main as
> int main(int, char**). 
> > However, let's not forget that Allegro never has
> done this and changing it 
> > may break existing code...
> 
> The problem is that the only main that should be int
> is the global main. 
> If you put a main in a class or struct, this method
> will fail horribly.
> 
> The only solution I can see is an al_main function
> or an AL_MAIN macro, 
> defined as such:

Renaming the macro to AL_MAIN would be a great idea. 
That way reverse compatibility could be preserved
aswell.  I don't know if that would just cause more
confusion though.

> #define AL_MAIN(...) \
> static int our_special_main(...); \
> int main(int argc, char *argv[], char *argz[]) /* or
> whatever */ \
> { \
>     do_our_magic_stuff(); \
>     return (*(int(*)(int,
> char*[],char*[]))&our_special_main)(argc, 
> argv, argz); \
> } \
> static int our_special_main(...)

It would be a better idea to prefix our_special_main
with an underscore.  We could even use _mangled_main.

> Since it's a macro (and a prefixed one at that), you
> don't really need 
> to worry about it being ued where we wouldn't expect
> by some obscure 
> user code somewhere. And also, if we take advantage
> of variable macro 
> arguments, we wouldn't force the user to use
> arguments they may not 
> want. Unfortunately, this requires C99 (what about
> C++?).

Forcing two arguments in the main function isn't all
that bad IMO, SDL does it, right?

Actually, how does SDL do it, do they have an
END_OF_MAIN() aswell?





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