为什么"小"会给出关于"char"的错误?

mal*_*avv 2 c++ visual-studio-2010 visual-studio-2012

尝试在运行QT5.4的Windows平台上用x86和x86_64编译VS2010,VS2012的开源项目.

名为unit.h的文件包含一个部分:

[...]
// DO NOT change noscale's value. Lots of assumptions are made based on this
// value, both in the code and (more importantly) in the database.
enum unitScale
{
   noScale = -1,
   extrasmall = 0,
   small = 1, // Line that causes errors.
   medium = 2,
   large = 3,
   extralarge = 4,
   huge = 5,
   without = 1000
};
[...]
Run Code Online (Sandbox Code Playgroud)

生成

  • 错误C2062:输入'char'意外
  • 错误C3805:'type':意外令牌,预期'}'或','

我试着用我的帽子解决它.我删除了代码中"小"枚举的每一次使用,我仍然得到错误.但在删除了所有用途后,我将"small"重命名为"smallo",一切都很好.它似乎表示名称冲突,但文件搜索在整个项目中没有给我任何引用.这不是我所知道的任何关键词.

有什么想法吗?

编辑:感谢非常有用的评论这里是一个更奇怪的版本,有效.有人可以解释一下吗?

#ifdef small // Same with just straight "#if"
#pragma message("yes")
#endif
#ifndef small
#pragma message("no") // Always prints no.
#endif

#undef small
enum unitScale
{
   noScale = -1,
   extrasmall = 0,
   small = 1,
   medium = 2,
   large = 3,
   extralarge = 4,
   huge = 5,
   without = 1000
};
Run Code Online (Sandbox Code Playgroud)

编辑2:pragma指令显示是,但仅在以前加载了windows.h标头的文件中,并且它在编译器输出中丢失了.感谢大家!真是个任务.

har*_*per 6

small是一个定义的rpcndr.h.它用作MIDL的数据类型.

  • 我们有赢家了!包含 windows.h -> winscard.h -> wtypes.h -> rpcndr.h -> 其中声明“#definesmall char”。 (4认同)
  • 这给很多开发者带来了巨大的痛苦。 (4认同)