Re: Does g++ really need to compile main, if c++ code is involved?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 03/20/2014 04:24 PM, schrieb Andy Falanga (afalanga):
-----Original Message-----

Can we get rid of this condition? For example by not using exceptions,
which are not caught and not using global/static non pod variables and
not using class wide non pod variables?

It's not exceptions only for which this is required.  C++ performs
> "name-mangling" on the symbols which doesn't happen in C.
> I'm not sure if I have enough context here to answer decisively,
> however, I think this FAQ link you've provided assumes that you're
> wishing to compile a C++ program and link with C sources.  It is
> possible to do the opposite.  Interestingly, the very FAQ you linked
> to says as much and that you should continue reading that section for
> how to perform this.  In fact, this link even states, "BTW there is
> another way to handle this whole thing: compile all your code (even
> your C-style code) using a C++ compiler."

I'm aware of name mangling. From C we only call C++-Functions, which have C compatible signatures and declarations wrapped in extern "C"
in the C++ code.

And we only call C functions from C++ code, whose declarations
are wrapped by extern "C" in the C++ code.

This all works well.

I really think, static initializations and exceptions are the problem,
because if I placed main in a C source file and compile it with gcc,
how are the initializations done? How are uncaught exceptions handled?

But there might be more, which I missed, so I asked here.

Using g++ for all the code is not an option. We want to use another
language, which insists on compiling the main function. So we really
want to ditch g++ for the file containing main.

I'll bet the rest of the FAQ in section 32 will be most interesting reading for you.

I'm aware of the rest of the FAQ.

Maybe I should rephrase the question:

If I want to write a library in C++ with an C interface and I don't want to force my clients to use the g++ compiler, what bits do I have
to pay attention to in the C++ code?

Yours sincerely,

Eric Wolf





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux