Re: [AD] New END_OF_MAIN() Proposal

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


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:

#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(...)

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++?).




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