Why? Call the C-compiled function in C + + and add extern "C" to the front of the Declaration

Source: Internet
Author: User

In a C + + program, call the function compiled by the C compiler, why do you want to add extern "C"in front of the declaration?

A:the C language does not support overloading, C + + supports overloading

In order to tell the compiler that this function is C's compilation style, so when looking for this function to follow the C style to find

For example: Write an Add function in C + +

int Add (int n1, int n2)

What did it find ? [email protected]@[email protected]

Function name @ @YA parameter parameter return value @z

h stands for int m for float

@ @YA means start @z end

Write an add function in the C language

int add (int n1, int n2)

It found the _add .


Why? Call the C-compiled function in C + + and add extern "C" to the front of the Declaration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.