By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
}
---------------------------------

Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Thu, 05 Aug 2004 13:10:01 +0800, Bill Zhao <sz*****@tom.com> wrote:
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
Jul 22 '05 #2

P: n/a
"Bill Zhao" <sz*****@tom.com> wrote in message
news:ce***********@mail.cn99.com...
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
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Jul 22 '05 #3

P: n/a
John Harrison ??:
On Thu, 05 Aug 2004 13:10:01 +0800, Bill Zhao <sz*****@tom.com> wrote:
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


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

Billz

Jul 22 '05 #4

P: n/a

"Bill Zhao" <sz*****@tom.com> wrote in message
news:ce**********@mail.cn99.com...

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.....
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.