[AD] Magic main on POSIX systems

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


No, I'm not obsessed with the Magic Main, but... ;-)

Let me re-state the problem:
- under Windows, the magic main is needed to provide the user with a ISO C
main(),
- on POSIX systems, the magic main is needed to initialize the library,
because there is no portable way of retrieving the name and
the path of the executable on POSIX systems, and Allegro needs both.
- under DOS and BeOS, the magic main is useless.

#1 is unavoidable and can be seen as a feature. But #2 is clearly a
limitation, and breaks under Darwin.

We already found that some libc (Linux, QNX) have global symbols we can
read. Now I just ran into another solution: using the /proc filesystem,
which usually exposes many informations. That's a way the newly released
Perl 5.8.0 RC1 chose, because they seem to have come across the very same
problem as ours.

Excerpt from http://use.perl.org/perldelta.html
"Rather than relying on C's argv[0] (which may not contain a full pathname)
where possible $^X is now set by asking the operating system. (eg by reading
/proc/self/exe on Linux, /proc/curproc/file on FreeBSD)"

So I propose that we further explore this path, so as to devise a method for
each OS we support (the Windows and BeOS ports already do so) and get rid of
the infamous Magic Main on POSIX systems.

--
Eric Botcazou
ebotcazou@xxxxxxxxxx



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