Re: why use extern "C"
Re: why use extern "C"
- Subject: Re: why use extern "C"
- From: Jens Alfke <email@hidden>
- Date: Tue, 07 Mar 2017 10:04:56 -0800
> On Mar 7, 2017, at 8:45 AM, bigpig <email@hidden> 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 inside can be called from C or C++ code.
If this “extern” declaration weren’t there, a C++ compiler would treat those functions as having C++ linkage, which means their names will be “mangled” to include information about their parameter types. That would cause a link error, because the program is referring to the function by a mangled name while the actual function has a plain C name.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden