Re: [AD] 3.9.34 release date? (args) |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Fri, 12 Jan 2001, Olly Betts wrote:
> I have heard that some pre-ANSI C compilers didn't set argv[argc] to NULL
> but Allegro really should.
As long as we are being technical, I felt that I would not let this
simplification slip ^_^
<PEDANTIC>
Actually, most C implementations have code called a CRT (C Run-Time),
which contains the real entry point of the executable. Your code does not
actually start running at main(), your main function is actually linked
into this CRT, which calls it just like any other function. Simplified,
it ussually looks like this:
int __crt_argc;
char** __crt_argv;
char** __crt_env;
void __crt_main (void)
{
int rv;
setup_standard_library_stuff();
get_args_from_os(&__crt_argc, &__crt_argv);
get_env_from_os(&__crt_env);
exit(main(argc, argv, env));
}
That is why when you don't provide a main, you don't get a special error,
it looks just like any other linker error.
</PEDANTIC>
So, you should have said that there where CRT that did not conform to the
ANSI standard. Most compilers don't actually treat main special at all,
they just automatically put crt0.lib or crt0.a at the very end of the
object list.
This is also why some programs compiled with some compilers crash if you
define main to be:
void main();
because the CRT was expecting main to return a value.
This is not a problem with the arguments, because say, if you declare main
as
int main(int argc)
it will still work because its okay for a caller to put more on the stack
than the calle needs.
Of course:
int main(int foo, char** bar)
{
}
works just as well.
It was an epiphany for me to realize that you don't have to call the
arguments to main argc, argv ^_^
The difference between WinMain and main, is that MSVC, or another windows
compiler, link with different versions of crt0 based on whether its a
windowed project or not.
There is actually no sound technical reason for this (at least, not since
1992 or so when NT came out), I think they did it just to make programs
harder to port.
> Cheers,
> Olly
--
The Phoenix -- The Artistic Intuition Company
Runica * Phoenix Quake * Caelius * Zen-X * Mirror Reflex * Infinite Realms