gpt4 book ai didi

c++ - 用宏确定 GCC 编译器

转载 作者:行者123 更新时间:2023-11-30 03:48:32 28 4
gpt4 key购买 nike

<分区>

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),但在我使用 TDM 进行编译的情况下,该宏将被错误地使用- Windows 上的 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.

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com