• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: why use extern "C"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >why use extern "C" (From: bigpig <email@hidden>)

  • Prev by Date: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Next by Date: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Previous by thread: Re: why use extern "C"
  • Next by thread: Re: why use extern "C"
  • Index(es):
    • Date
    • Thread