By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Andy" <gn***@yahoo.com> wrote...
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
Jul 23 '05 #2

P: n/a

Victor Bazarov wrote:
"Andy" <gn***@yahoo.com> wrote...
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.
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

Jul 23 '05 #3

P: n/a
msalters wrote:
Victor Bazarov wrote:
"Andy" <gn***@yahoo.com> wrote...


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.

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.
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.


You're absolutely right, of course.

V
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.