不同 Fortran 和 C 供应商之间的 ISO_C_BINDING

发布于 2025-01-05 11:25:45 字数 266 浏览 0 评论 0原文

C/C++ 编译器供应商是否也支持 Fortran ISO_C_BINDING 模块的概念?例如,C/C++ int 的大小可能因不同供应商的编译器而异。因此,通过 ISO_C_BINDING 模块,我们知道 Fortran C_INT 类型是 4 个字节;而不仅仅是 4 的种类。但是,我们仍然不知道 C/C++ 中 int 的大小。我说得对吗?是否有一个标准的 C/C++ ISO_C_BINDING 兼容编译器开关?

Is the concept of the Fortran ISO_C_BINDING module also supported by C/C++ compiler vendors? For example, the size of a C/C++ int can vary between the compilers from different vendors. So, with the ISO_C_BINDING module, we know that a Fortran C_INT type is 4 bytes; rather than merely having a kind of 4. But, we still don't know the size of an int in general in C/C++. Am I correct? Is there perhaps a standard C/C++ ISO_C_BINDING-compatible compiler switch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦慕雪 2025-01-12 11:25:45

据我所知,该标准只要求同一工具链中的匹配类型。因此,您最好使用同一供应商的 C 编译器。我认为该标准没有声明任何有关 C_ 类型大小的信息。

编辑:刚刚在标准中查了一下,它总是在谈论配套的 C 编译器。

As far as I know, the standard only demands matching types in the same toolchain. Thus you are better using the C-Compiler from the same vendor. The standard doesn't claim anything about the sizes of the C_ kinds, I think.

Edit: Just looked it up in the standard, it is always talking about the companion C-compiler.

兔小萌 2025-01-12 11:25:45

大多数操作系统都会公开 C API,这显然意味着该平台上存在标准 C ABI。通常,C 编译器使用此 ABI,但可能存在一些特殊性(例如,Windows API 的标准调用约定是 stdcall,它不支持可变参数函数,因此有第二个主要调用约定,称为 cdecl)。

C++ 的情况并不那么明确:大多数操作系统不公开 C++ API(有 BeOS/Haiku 等例外),因此编译器供应商可以自由地做他们认为最好的事情,导致不同编译器之间的不兼容供应商之间,有时甚至是同一编译器的不同版本之间。我认为至少GCC已经稳定了他们的C++ ABI,但我不知道总体情况......

Most operating systems expose a C API, which obviously implies the existence of a standard C ABI on that platform. Normally, C compilers use this ABI, but there may be some peculiarities (eg, the standard calling convention for the Windows API is stdcall, which doesn't support variadic functions, thus there's a second major calling convention called cdecl).

The situation for C++ isn't as clear-cut: most operating system do not expose a C++ API (there are exceptions like BeOS/Haiku), thus compiler vendors were free to do whatever they thoght best, leading to incompatibilities between compilers from different vendors and sometimes even between different versions of the same compiler. I think at least GCC has stabilized their C++ ABI, but I have no idea about the general situation...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文