gpt4 book ai didi

c - 这个#ifdef __GNUC__ 是关于什么的?

转载 作者:IT老高 更新时间:2023-10-28 22:59:11 24 4
gpt4 key购买 nike

我在 the libmagic code 中找到了这些行.它们是什么意思?

#ifdef __GNUC__
__attribute__((unused))
#endif

__GNUC__ 是什么意思?
好像检查whether GCC is installed .

什么是__attribute__((unused))
这里有一个代码片段,但没有解释:How do I best silence a warning about unused variables?

__GNUC___MSC_VER有什么区别?
_MSC_VER 上面有一些解释,但到底是什么?
How to Detect if I'm Compiling Code with a particular Visual Studio version?

最后一个问题:
如何执行相同的 #ifdef 来检查哪个编译器正在编译我的代码?

最佳答案

在编译器中定义宏来确定它们是什么编译器、版本是什么是很常见的……可移植的 C++ 代码可以使用它们来确定它是否可以使用特定的功能。

What does __GNUC__ mean?

这表明我是一个 GNU 编译器,你可以使用 GNU 扩展。 [1]

 

What is __attribute__((unused))?

附加到变量的此属性意味着该变量可能未被使用。 GCC 不会为此变量生成未使用的变量警告。 [2]

 

What is the difference between __GNUC__ and _MSC_VER?

它们是两个不相关的宏。第一个说我是 GNU 编译器,第二个说 MS 编译器的版本号。但是,MS 编译器不应该支持 GNU 扩展。

 

How can I do the same #ifdef to check whether OS is compiling my python code using GNU and MS visual studios?

#if (defined(__GNU__) && defined(_MSC_VER))
// ...
#endif

但是,没有机会同时具备这些条件!

关于c - 这个#ifdef __GNUC__ 是关于什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19908922/

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