473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
3 2969
"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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Shea Martin | last post by:
I am trying to use a system call which takes a function ptr. My compiler won't compile the code if I give the system_call a ptr to a class member function, A::func(). To combat this, I created an...
1
by: terrencel | last post by:
I was told to look at some old C code that was ported to C++. One of the file is like: ========================================= CPPClass* someCPPVar = NULL; extern "C" {
4
by: cpptutor2000 | last post by:
Could some C++ guru help me please? I am trying to build an application using gcc 3.2.3, that has a some classes using functions defined in some C files in the same directory. If inside the C++...
9
by: Marek Kurowski | last post by:
Yo! What mean when program is ALPHA or BETA version? I suppose it is not release version of program, but I don't know what it exactly mean. What it mean in your opinion? Marek Kurowski
12
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
4
by: kk_oop | last post by:
Hi. I need to write a C++ callback function and register it with a C program. I've read that this can be done if the callback function is a static method. I've also read that I should use a...
9
by: plusk1008 | last post by:
I have finals next week and I am stuck on one question on my review sheet for excel. So once again I beg: Please, please, please, please, please, please, please, please, please, please someone help...
4
by: chandanlinster | last post by:
hello everybody, as i was going through the "printf" man page, i came across this statement. printf("%*d", width, num); what does "*" mean?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.