gpt4 book ai didi

c++ - "#define bool bool"当我悬停 bool 时说 QtCreator - 我将其跟踪到 boost::asio

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:51:48 27 4
gpt4 key购买 nike

我注意到 bool在 QtCreator 中以不同于其他类型的颜色突出显示:

image description

只有在包含某些 header 时才会发生这种情况,最终我将其追踪到 <boost/asio.hpp> . QtCreator 的代码检查器似乎无法手动跟踪定义。我使用的boost版本是Boost 1.59。

这样做有什么目的吗?我真的不介意,但是为同一事物定义任何东西是相当奇怪的,而不是 bool .

最佳答案

好吧,我搜索了 Boost 1.59 代码,看看是否可以找到:#define bool bool#include <stdbool.h>但我最终没有找到它们,所以它可能在这些文件中,但很可能在其他地方。


Is there any purpose for that? I don't really mind it but it's rather strange to define anything to the same thing, more than a bool.

想象一下包含如下内容的代码:

#define bool int
// The next line would change the previous definition
#define bool bool

然后有:

#ifndef bool
#elif bool
#endif
// etc..

这将是尝试移植 C 程序的一种非常丑陋的方式(考虑到在 C++ 中不允许重新定义关键字)。


这可能来自 stdbool.h 的包含。其中包含此确切内容 ( atleast on clang )。我个人认为这要么是 ide/highlighter/parser 中的错误,要么是包含此 header /代码的文件。

如果您在这些设置下没有收到警告,很可能这段代码实际上没有被使用,而只是解析错误:

不确定 GCC -Wall 似乎没有注意到它。

关于c++ - "#define bool bool"当我悬停 bool 时说 QtCreator - 我将其跟踪到 boost::asio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35038583/

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