EDIT: Ha ha, search terms are a weird thing. I actually had to use the answer I got as a term for the search to finally find this question. In the spirit of StackOverflow, I'll vote to close my own question as duplicate instead of deleting it, in case it'll serve as a landing point for someone else.
我正在编写几个使用 asm
的函数,但我只希望它们在使用可与 NASM 配合使用的编译器编译时才能运行。 (顺便说一下,我使用的是 C++11。)
我对 asm
的整个概念有点陌生,但这就是我认为我所知道的:
- GCC 及其“亲戚”(MinGW、TDM-GCC)使用 NASM,这就是我编写函数的目的。
- 理论上,无论操作系统如何,所有 Intel 和 AMD 处理器都可以理解 NASM,因为...
- X86/X64 汇编器由编译器实现的内容决定。
假设上述内容是正确的,当且仅当我使用 GCC(或类似)编译器或使用 NASM 的编译器时,我可以使用什么宏来确保定义我正在编写的函数?(#ELSE
将是该函数的可用虚拟版本,以确保与其他编译器的总体兼容性。)
我所知道的唯一此类宏与确定操作系统有关(例如 #IFDEF _WIN32
),但在我在 Windows 上使用 TDM-GCC 或 MinGW 进行编译的情况下,该宏会错误地使用。
NOTE: In case anyone wonders, the functions in question are basically "helpful, but not vital" utility functions. We don't have any plans to compile with a non-GCC compiler, but it's open source code, so we want to be considerate of others.
最佳答案
您可以使用__GNUC__
宏来识别 GCC(以及一些主要兼容的编译器,如 Clang 和 Intel 的 C++ 编译器)。
MinGW(任何版本)可以检查 __MINGW32__
和/或 __MINGW64__
。
关于c++ - 用宏确定GCC编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33158278/