---Hi, what mean, what help it can do?

B

Bill Zhao

Hi,
I am browsing the source codes and it include the below code in a .h file
somebody can tell me what the codes below mean ?

Bill Zhao
----------------------------------
#ifdef __cplusplus
extern "C"
{
xxxxx
xxxx
.......
xxxxx

#ifdef __cplusplus
}
---------------------------------
 
J

John Harrison

Hi,
I am browsing the source codes and it include the below code in a .h
file
somebody can tell me what the codes below mean ?

Bill Zhao
----------------------------------
#ifdef __cplusplus
extern "C"
{
#endif

xxxxx
xxxx
......
xxxxx

#ifdef __cplusplus
}
#endif


It means the header declares routines and data which are written in
C++ but are callable from C or C++. Lookup __cplusplus and extern "C" in
your favourite C++ book.

john
 
I

Ivan Vecerina

Bill Zhao said:
I am browsing the source codes and it include the below code in a .h file
somebody can tell me what the codes below mean ? ....
#ifdef __cplusplus
extern "C"
{

<< extern "C" >> is used to tell a C++ compiler that the following
declaration/function(s)
are to be linked using C conventions (i.e. without name mangling).
This is typically used to allow a library to be used from both C and C++.
( NB: the function implementations themselves may be written
in either C or C++ ).

When a C compiler is used, << extern "C" >> would be a compile error and is
unnecessary. So the << #ifdef __cplusplus ... #endif >> is used to hide the
extern "C" from a non-C++ compiler.

Ni hao -ivan
 
B

Bill Zhao

John Harrison ??:
It means the header declares routines and data which are written in C++
but are callable from C or C++. Lookup __cplusplus and extern "C" in
your favourite C++ book.

john

thank you indeed and I can go ahead my work.
I only have a very short book of c++.

Billz
 
J

jeffc

Bill Zhao said:
thank you indeed and I can go ahead my work.
I only have a very short book of c++.

Maybe buy a longer book if you will be doing much more work.....
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top