What does 'extern "C++" ' mean?

A

Andy

Hi,

This is just a simple hello world program.

#include <iostream>
using namespace std;
int main()
{
cout<<"Hello,world\n";
}


Today I happened to look into the intermediate code genernated by
preprocessor. I found there is code like the follows:

extern "C++"{
.....
}
Why we need such code? I am using gcc-3.4.2.

Thanks a lot!

Andy
 
V

Victor Bazarov

Andy said:
This is just a simple hello world program.

#include <iostream>
using namespace std;
int main()
{
cout<<"Hello,world\n";
}


Today I happened to look into the intermediate code genernated by
preprocessor. I found there is code like the follows:

extern "C++"{
....
}
Why we need such code? I am using gcc-3.4.2.

The only thing I can think of is that the module where you found that
construct is in fact a C module, not a C++ module, like the result of
the front-end (translator) work, which creates C code from C++ code for
the C compiler to digest and convert to object code. I don't know if
gcc uses that approach, but I know that Comeau C++ does, for example.

The language specification ("C++") in the 'extern' declaration is the
default for a C++ compiler, and explicit mentioning it probably makes no
difference in a C++ program.

V
 
M

msalters

Victor said:
The only thing I can think of is that the module where you found that
construct is in fact a C module, not a C++ module, like the result of
the front-end (translator) work, which creates C code from C++ code for
the C compiler to digest and convert to object code. I don't know if
gcc uses that approach, but I know that Comeau C++ does, for example.

I'm not fully up-to-date with C99, did it get extern "C++" ?
I know that C94 doesn't even have extern "C'.
The language specification ("C++") in the 'extern' declaration is the
default for a C++ compiler, and explicit mentioning it probably makes no
difference in a C++ program.

There's one case whene it does, inside an extern "C" { } block.
A simple preprocessor may not be aware of such surrounding blocks.
Regards,
Michiel Salters
 
V

Victor Bazarov

msalters said:
I'm not fully up-to-date with C99, did it get extern "C++" ?
I know that C94 doesn't even have extern "C'.

No, C99 doesn't have that. For some reason I decided to assume that.
My mistake.
There's one case whene it does, inside an extern "C" { } block.
A simple preprocessor may not be aware of such surrounding blocks.

You're absolutely right, of course.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top