English 中文(简体)
C++改为“C”类 ex变问题
原标题:C++ to Java conversion question about extern "C"
  • 时间:2011-06-30 21:04:58
  •  标签:
  • java
  • c++
  • c

我不得不将一些C/C++代码转换到 Java。 我的C++极其隐蔽。

在<代码>h文档中,我有:

#ifdef __cplusplus
extern "C" {
#endif

/* tons of declarations */

#ifdef __cplusplus
} /* extern C */
#endif

如何使用<代码>extern“C”? 它意味着什么? 它是否告诉汇编者,相应的法典应当被解释为纯C,而不是C++?

http://www.ohchr.org。

Thanks for the answers so far. The history of the code I have to convert is that it seems like a part was written in C first, then the rest was written in C++. So my header file seems to correspond to old C code.

I ll 将这一代码改为的公开最终类别,其中采用静态方法和属性。 不得凌驾于一切。

最佳回答

It s telling the compiler that function signatures should be C compatible. Name mangling are different in C and C++ (i.e. C++ supports method overloading while C does not) so in order to make some function calls (i.e. some DLL dynamic calls) compatible with C signature, you use extern C in C++ code.

,Take a look at this StackOverflow question for a grand interpret on the话题

问题回答

<代码>Extern “C”用于表示一种C型连接而不是C++式连接。 C++汇编者在功能符号上增加了类型信息,但C汇编者没有。

如果必须用外部应用程序使用你的图书馆,extern "C"是强制性的,因为C++汇编者在类型信息方面大多不兼容。 比如,在 Java,你必须创造本土执行。

外部“C”指的是一种连接风格,而不是一种C++风格。 它告诉汇编者,“请不要把我的职能名称混为一谈”。 采用这一方法,可将C++方案与C方案联系起来。 如果你将一些东西转换到 Java,那么忽视这一点可能是安全的。 只有当你试图将法典转换为C或C++时,这一行将是重要的。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签