Re: why use extern "C"

2017-03-12 Thread Uli Kusterer
On 7 Mar 2017, at 17:45, bigpig wrote: > I see some code like this in iOS project: > > #ifdef __cplusplus > extern "C" { > #endif Others have mentioned what this code does, but I think it'd be useful to provide some background why this is needed: In C, functions are distinguished by name. A fu

Re: why use extern "C"

2017-03-07 Thread Jens Alfke
> On Mar 7, 2017, at 8:45 AM, bigpig wrote: > > if there is C++ compiler and use C linkage,but if there isn’t C++ compiler > then use what? Then it’s a C compiler, which obviously uses C linkage. > And what is the reason of using this way in code? To make sure that the functions declared ins

Re: why use extern "C"

2017-03-07 Thread Charles Srstka
> On Mar 7, 2017, at 11:42 AM, Aandi Inston wrote: > > (You should not see // in this section, because in pure C it is forbidden). This is not true with the latest versions of the C standard. Both C99 and C11 support inline // comments. The only case where // is not allowed is if someone is u

Re: why use extern "C"

2017-03-07 Thread Aandi Inston
This is common practice. Here's why. In C++ this #ifdef __cplusplus extern "C" { #endif ………./*some function,struct*/ #ifdef __cplusplus } #endif compiles as extern "C" { ………./*some function,struct*/ } As you identify, this declares C linkage, usually to a precompiled C library, or to make a C-

why use extern "C"

2017-03-07 Thread bigpig
I see some code like this in iOS project: #ifdef __cplusplus extern "C" { #endif ……….//some function,struct #ifdef __cplusplus } #endif if there is C++ compiler and use C linkage,but if there isn’t C++ compiler then use what? And what is the reason of using this way in code? Thanks! _