473,386 Members | 1,835 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,386 software developers and data experts.

extern "c" usage?!!

What's that preprocessor do
#ifdef __cplusplus
extern "C" {
#endif
..
..
..
#ifdef __cplusplus
}
#endif

and how you say extern "C" , i mean how u extern constant!!
Jul 6 '08 #1
5 2906

"Medvedev" <3D********@gmail.comwrote in message
news:7f**********************************@t54g2000 hsg.googlegroups.com...
What's that preprocessor do
#ifdef __cplusplus
extern "C" {
#endif
.
.
.
#ifdef __cplusplus
}
#endif

and how you say extern "C" , i mean how u extern constant!!
extern "C"
{

}

... causes any functions inside the braces to have
"C linkage", so that they can be called from C
functions. There's nothing about 'constant' here.

The #ifdef will cause 'extern C' to be applied only
if translating C++ code.

-Mike
Jul 6 '08 #2
On Jul 6, 2:12 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
"Medvedev" <3D.v.Wo...@gmail.comwrote in message

news:7f**********************************@t54g2000 hsg.googlegroups.com...
What's that preprocessor do
#ifdef __cplusplus
extern "C" {
#endif
.
.
.
#ifdef __cplusplus
}
#endif
and how you say extern "C" , i mean how u extern constant!!

extern "C"
{

}

.. causes any functions inside the braces to have
"C linkage", so that they can be called from C
functions. There's nothing about 'constant' here.
sorry , but what differ C++ functions from C ones
Jul 6 '08 #3
"Medvedev" <3D********@gmail.comwrote in message
news:ce**********************************@e53g2000 hsa.googlegroups.com...
On Jul 6, 2:12 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
>"Medvedev" <3D.v.Wo...@gmail.comwrote in message

news:7f**********************************@t54g200 0hsg.googlegroups.com...
What's that preprocessor do
#ifdef __cplusplus
extern "C" {
#endif
.
.
.
#ifdef __cplusplus
}
#endif
and how you say extern "C" , i mean how u extern constant!!

extern "C"
{

}

.. causes any functions inside the braces to have
"C linkage", so that they can be called from C
functions. There's nothing about 'constant' here.

sorry , but what differ C++ functions from C ones
C++ functions have overloading. C functions do not. This means there is
only one definition for a C function, there can be more than one for a C++
function. Compilers typcially handle this by "mangling". This will change
the name of the C++ function in the object file so the linker can
differentiate between calling parameters.

stating:
extern "C" {
tells the compiler not to mangle the function names, there will only be one
declaration for each function, so then when it is linked it has C linkage,
the function name would be the same as if it was a C function, and C
programs/objects can call the function as they can now link to them.
Jul 6 '08 #4

"Medvedev" <3D********@gmail.comwrote in message
news:ce**********************************@e53g2000 hsa.googlegroups.com...
On Jul 6, 2:12 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
>"Medvedev" <3D.v.Wo...@gmail.comwrote in message

news:7f**********************************@t54g200 0hsg.googlegroups.com...
What's that preprocessor do
#ifdef __cplusplus
extern "C" {
#endif
.
.
.
#ifdef __cplusplus
}
#endif
and how you say extern "C" , i mean how u extern constant!!

extern "C"
{

}

.. causes any functions inside the braces to have
"C linkage", so that they can be called from C
functions. There's nothing about 'constant' here.

sorry , but what differ C++ functions from C ones
Think about overloading. You can have more than a
single function with the same name (the number and/or
types of arguments would differ.

int foo(void);
int foo(int);
int foo(int,int);

C++ needs to distinguish these functions from one another.
There's no specific method required by the standard, but
typically the compiler will 'mangle' the names (change and/or
add characters) so that they become unique.

"extern C" prevents this 'mangling', so that the function
can be linked with C (using its 'real' name).

Anyway, I should have already cited this link from the C++ FAQ:
http://www.parashift.com/c++-faq-lit...c-and-cpp.html

This explains it better than I.

-Mike

Jul 6 '08 #5
On Jul 7, 12:18 am, Medvedev <3D.v.Wo...@gmail.comwrote:
On Jul 6, 2:12 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
"Medvedev" <3D.v.Wo...@gmail.comwrote in message
news:7f**********************************@t54g2000 hsg.googlegroups.com....
What's that preprocessor do
#ifdef __cplusplus
extern "C" {
#endif
.
.
.
#ifdef __cplusplus
}
#endif
and how you say extern "C" , i mean how u extern constant!!
extern "C"
{
}
.. causes any functions inside the braces to have
"C linkage", so that they can be called from C
functions. There's nothing about 'constant' here.
sorry , but what differ C++ functions from C ones
Whatever the implementation wants. There's no fundamental
reason for two different languages to use the same calling
conventions. One typical difference might be that in C++, the
call stack is cleaned up in the called function (since it
involves calling destructors, etc.), where as in C, it is
cleaned up in the callee (since historically, C didn't have
prototypes, and allowed calling a function with extra arguments,
which were ignored). Also, C++ has overloading, which means
that some sort of information concerning the type and number of
arguments must be maintained in the object file. And because C
allowed extra arguments, a C compiler will not want to do this.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 7 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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" {
11
by: Daniele Benegiamo | last post by:
Is the following program standard-compliant? I've compiled it with some compilers and no errors or warnings are produced, but this is not a demonstration. The "incriminated" part is the...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
5
by: Vijay Kumar Zanvar | last post by:
Hello I have seen in many source files the usage of extern +ACI-C+ACI-. What is its purpose? Thanks VRZ
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...
5
by: jchludzinski | last post by:
I have 3 files (see below: a.h, w.c, ww.c). I would like to use a single x (declared somewhere) which would global to both compilation units: w.c & ww.c. No matter where I place the "extern"...
2
by: Christoph Conrad | last post by:
Hi, given the following test case, with CString from Microsofts MFC: ================================================== file 1: CString arr; ...
4
by: mimi | last post by:
The programmer indicates to the compiler that a function is written in a different programming language using a linkage directives.It is intuitive that extern "SomeLanguage" is used to declare...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.