Is there something like extern "CPP" ?
Jonathan Wakely
jwakely.gcc@gmail.com
Tue May 27 09:39:00 GMT 2014
On 27 May 2014 07:07, de Brebisson, Cyrille (Calculator Division) wrote:
> Hello,
>
> I have megabytes of sources which follow the C++ syntax rather than the C s= yntax.
> These are NOT 'real' C++ sources (no objects, they just use C++ syntax).
What's the difference? If it uses C++ syntax it's a C++ source.
> Unfortunately I have to migrate to a different development environment whic= h uses gcc in the back end, BUT only as a C compiler. In this new system, I= have NO access to the makefile, nor the command line used to call gcc.
>
> The question, is: how, IN the .c file, do I tell gcc that the code bellow s= hould be parsed/compiled using the C++ syntax (the only thing I can touch b= eing my source files...)
That's not possible.
That's not what extern "C" does in C++ anyway. It only tells the
compiler to make functions callable form C, it has no effect on the
syntax used, it does *not* tell the compiler to work as a C compiler.
For example, this is valid C++ despite using classes, virtual
functions, references and exceptions in an extern "C" block:
#include <stdexcept>
extern "C" {
class Foo {
virtual void f();
};
void func(const int&) {
throw std::runtime_error("");
}
}
>
> Can I do something like
> extern "CPP" {
> My code
> }
> (ok, I do know that extern, as a concept, is not exactly what I am looking for, but I was trying to find something close enough that people would understand).
It's not close, because you seem to misunderstand what extern "C" does.
> Or is there a #pragma for this?
No.
> Command lines options are unfortunately not workable for me...
Then your only option is to rename the files to use an extension that
GCC recognises as C++, such as .cc, .C, .cpp etc.
More information about the Gcc-help
mailing list