Re: [AD] END_OF_MAIN, again

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


On 8/10/05, Chris <chris.kcat@xxxxxxxxxx> wrote:
No it won't. You can have a C function and C++ function using the same name
and same arguments. Because C and C++ uses different mangling, the linker
will see them as two different functions. The only problem comes in if you
declare them both in the same file and try to use it, the compiler becomes
confused over which one you want.

extern "C" int _mangled_main(int argc, char **argv);

int _mangled_main(int argc, char **argv)
{
   return 0;
}

That's acceptable C++ code, and will leave the C-style _mangled_main
undefined.


extern "C" void foo(int argc, char **argv);
void foo(int argc, char **arg) {}
void foo() {}

g++ -c test.cpp -o test.o
objdump -t test.o

[  2](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 1) 0x00000000 _foo // First foo that match prototype
[  4](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000010 __Z3foov

Same thing for MSVC, so you can see it works.
 

AFAIK, forcing the user to use a specific main type is unnacceptable.
Especially since it'd break existing programs.

It's for C++ only and it's small change ( int main() => int main(int, char **) ).
Other solution is dummy C++ file.


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