Function of C ++ extern "C"

Source: Internet
Author: User

1. The function of extern "C" is used to tell the compiler that the function is written in C language.
Ii. Use the following methods:

1. extern "C" Void exit (INT) // containsC LanguageThe exit function.
2. extern "C"

{

Int printf (const char *....);

Int scanf (char *...);

....

} // Contains a group of functions written in C language.
3. extern "C" {# include <cmath>} contains functions in the Standard C library.

Iii. Supplement

1. extern can be placed before the variable Declaration; 2. extern can also be placed before the function declaration; through this behavior, it tells the compiler that the definition of the variable/function already exists somewhere, let the compiler look for its definition in other modules. 3. extern "C" uses extern "C" mainly because the C ++ language implements polymorphism during compilation, function names and functions are combined to form another function name (in short, the compiled function name is different from the one you previously declared ), the concept of no polymorphism in C Language certainly does not have this strange name change problem. This is the problem. When you want to call the C function in C ++, because of the different names, it will not find the definition of the called function, therefore, an error occurs. To solve the conflicts between C and C ++, the extern "C" extern exists ".

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.