Re: [AD] Proposal for new magic main |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Thu, Feb 21, 2002 at 03:29:24PM +0100, Eric Botcazou wrote:
> > But it would be nice to allow initialization of most parts of Allegro
> > without these 'main' tricks, by passing (argc, argv) to allegro_init
> > (or al_init_system (argc, argv, ...)), or something like that.
>
> But there is not such argc/argv for GUI apps under Windows. And the magic
> main trick is not intended to initialize Allegro, but precisely to provide a
> portable executable_name/argc/argv framework to Allegro programmers.
IMHO, the executable name is pretty irrelevant, but that's a
side issue. If the only point of the trickery is to provide
access to arguments and a common syntax for the entry point,
then surely Windows is the only awkward platform -- all we need
to do is let the user write a main function as normal, and
supply a WinMain function which calls it passing the appropriate
arguments (as Allegro 4 already does). IIRC the only problems
with that were (a) that RSXNTDJ uses presence of `main' to
decide whether to do a console app (but we don't have a RSXNTDJ
port any more), and (b) that WinMain doesn't work from inside a
DLL, so needs inserting into the user code. I think END_OF_MAIN
was intended just to ensure this was done at precisely one place
in the program. So perhaps it's sufficient to just do something
like:
#define main \
WinMain(parameters) \
{ \
stuff to call main \
} \
int main
on Windows only? I don't like defining `main' though, we could
equally well provide exactly the current END_OF_MAIN define,
which does nothing on any system except Windows where it inserts
the WinMain entry point.
It's up to you guys what you do, but it has irritated me in the
past that Allegro on Unix seems to interfere with `main' for the
sole purposes of things which are essentially pointless
(returning the executable name, and setting __crt0_argc and
__crt0_argv, which aren't useful to the user since they were
passed on to the main function anyway). If you're redesigning
the API it strikes me this would be a nice thing to get rid of.
:)
However, if Allegro must #define main on any system, it might as
well do it on all because portable code still couldn't use it in
structs or as a parameter or variable name. And if only one
platform needs END_OF_MAIN, nobody will bother with it on other
platforms. :( Argh, I hope by now the people who designed the
first Windows API have found jobs better suited to their lack of
foresight.
George