English 中文(简体)
C++ 外部“C”功能
原标题:C++ s extern-"C" functionality to languages other than C

众所周知,宣布<代码>extern “C”至C++功能使其名称具有C联系,使C代码能够链接。

我的问题是——是否有其他方案语言,我们能够使C++的功能名称与诸如<代码>extern“Lisp<>/code>或extern“FORTRAN”等内容联系起来?

如果不是,为什么? 什么是限制在<代码>C>后面的内部结构?

有哪些替代办法?

最佳回答

C++标准,7.5.2 dcl.link:

Linkage between C++ and non-C++ code fragments can be achieved using a linkage-specification:

linkage-specification:
    extern string-literal { declaration-seqopt}
    extern string-literal declaration

The string-literal indicates the required language linkage. This International Standard specifies the semantics for the string-literals "C" and "C++". Use of a string-literal other than "C" or "C++" is conditionally supported, with implementation-defined semantics. [ Note: Therefore, a linkage-specification with a string literal that is unknown to the implementation requires a diagnostic. —end note ] [ Note: It is recommended that the spelling of the string-literal be taken from the document defining that language. For example, Ada (not ADA) and Fortran or FORTRAN, depending on the vintage. —end note ]

因此,原则上,执行者可以选择支持C和C++以外的其他联系规格。

In practise however, on all modern platforms, C linkage is the lowest common denominator. As a general rule, these days, binary interop for languages other than C uses C linkage. On the widely used modern platforms, you will not see anything other than C and C++ linkage.

问题回答

现代C++的编纂者不支持ISO C++标准所要求的“编码”和<代码>extern“C++”。 与其他语文的结合最常用的是C呼唤公约和extern “C”

And even when non-C calling conventions were supported, they often weren t selected by an extern string literal, they still used extern "C" but in conjunction with some non-standard calling convention declaration: for example, Microsoft C++ for 16-bit platforms (DOS, Windows 3.x, OS/2 1.x) used __pascal for the Pascal calling convention and __fortran for Fortran, instead of something like extern "Pascal" or extern "Fortran".

That said, IBM s contemporary C++ compilers for z/OS support extern "FORTRAN" for calling Fortran, extern "COBOL" for calling COBOL, and extern "PLI" for calling PL/I.

同样,IBM公司i 的ILE C++汇编者支持一份不同的<代码>extern清单。 stringlichs, see PDF page 338 of ILE C/C++ Programmer s Guide , such as extern "RPG", extern "C nowiden” (即extern "C",但转而转而通过,因此,short将实际作为2条而不是4条通过),(从而使IBM的遗产前ILE打公约)。

现在看来,IBM是唯一支持非<条码>C”的C++主要供应商。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签