472,958 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2940
"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?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.