From: ranjit_mathew <rm...@ho...> - 2002-05-24 05:16:15
|
--- In mingw-users@y..., Greg Chicares <chicares@m...> wrote: > > But main() is unique. It's C[++]'s interface to the loader. > You can't call it. I can't? Well, this program compiles and runs just fine with "gcc -Wall" on MinGW 1.1 (gcc 2.95.3-6): ------------------------ 8< --------------------- #include <stdio.h> void foo( void); int main( int argc, char *argv[]) { if( argc == 23) printf( "Hello World!\n"); else foo( ); return 0; } void foo( void) { main( 23, NULL); } ------------------------ 8< --------------------- :-P > so code generation already has to distinguish it from other > functions. Nope. Code *compilation* has to distinguish it from other functions, as well as the code *linked* with it. Nitpicking... > > The call to __main( ) looks like a kludge to me - I > > just cannot understand why #ifdefs in the C startup code > > cannot achieve the same effect in the GCC source. > > It's a common technique; here's how one vendor explains it > http://www.hh.se/stud/d98rolb/ansi/__main().html > It's just an implementation choice. From that page, it appears to be a part of the C startup code and I have no problems at all with that. I'm uncomfortable when it generates a call to this from within "my" main( ). > Usually I want what _main() provides. But you can hack > the sources to get something different. Maybe you can > hack them enough to get something like this > > > unsigned char main[] = { > > 0x55,0x89,0xe5,0x56, 0x53,0x83,0xec,0x50, > ... > > 0x00,0x83,0xc4,0x50, 0x5b,0x5e,0x5d,0xc3 > > }; > > to do what you want, but all the standard requires mingw > to do with that program is to emit at least one diagnostic. Once again, even "gcc -Wall" does not give any warnings/errors with the program above (again MinGW 1.1, gcc 2.95.3-6). Ranjit. http://groups.yahoo.com/group/mingw-users/ (mingw-users on Yahoo! Groups) |