> You need to do it to interface to any library written in C (such as > the standard C library for example). For example, try the following > C++ code with and without 'extern "C"'. Without it, you won't be able > to link. Fortunately, all your system headers already provide you with > 'extern "C"' by default. > > extern "C" void exit(int); > int main() > { > exit(0); > }
Thank you for the information. However, I was able to compile and link with and without 'extern "C"' using GCC 3.3.3 on a system running GNU/Linux (SuSE). I couldn't link when I compiled with `g++' and tried to link with `gcc', but the error didn't seem to have anything to do with the problem under discussion: mangle.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' Am I missing something here? Clearly, `extern "C"' has a purpose, or it wouldn't exist. Does GCC do something special, or have I done something wrong? It seems to me that if a compiler doesn't mangle any "unqualified" names, i.e., ones declared outside of a namespace or a class, it should be possible to link with the object file in which they are defined without the linker having to do anything special. However, it's been a long time since I read anything about this subject and this may be naive. Laurence On Fri, 28 Nov 2008, Samuel Tardieu wrote: > >>>>> "Laurence" == Laurence Finston <[EMAIL PROTECTED]> writes: > > Laurence> One thing you might have to look out for is "name-mangling" > Laurence> which C++ compilers do. You might have to turn it off for C > Laurence> code by specifying C-linkage, e.g., "extern "C" foo(void);". > Laurence> I've never had to do this for my own code, but I've seen it > Laurence> in other people's. I would have to review when it's > Laurence> necessary; I don't know off the top of my head. > > You need to do it to interface to any library written in C (such as > the standard C library for example). For example, try the following > C++ code with and without 'extern "C"'. Without it, you won't be able > to link. Fortunately, all your system headers already provide you with > 'extern "C"' by default. > > extern "C" void exit(int); > int main() > { > exit(0); > } > > > > _______________________________________________ > help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison > _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison