extern "c" usage?!!

M

Medvedev

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!!
 
M

Medvedev

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
 
J

Jim Langston

Medvedev said:
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.
 
J

James Kanze

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.
 

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
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top