Description of Extern "C"

zhaozj2021-02-16  85

Mixed-language programming with c

C uses the same calling convention and parameter-passing techniques as C, but naming conventions are different because of C decoration of external symbols. By causing C to drop name decoration, the extern "C" syntax makes it possible for a C module to share Data and routines with other languages.

.

Extern "C" {void prn ();

To Call Functions Written in Fortran (Or Masm), Declare The Function As you would in c and use a "c" Linkage Specification. For Example, To Call The Fortran Function Fact from C , Declare IT As Follows:

Extern "C" {INT __STDCALL FACT (INT N);

The extern "C" syntax can be used to adjust a call from C to other languages, or to change the naming convention of C routines called from other languages. However, extern "C" can be used only from within C . If the C code does not use extern "C" and can not be changed, you can call C routines only by determining the name decoration and generating it from the other language. you can always determine the decoration by using the DUMPBIN utility. use this approach only as a Last Resort, Because The Decoration Scheme Is Not Guaranteed To Remain The Same Between Versions.

Use of extern "C" HAS Some Restrictions:

You Cannot Declare a Member Function with Extern "C".

转载请注明原文地址:https://www.9cbs.com/read-12124.html

New Post(0)