简体   繁体   English

C ++中的“undefine”模块关键字

[英]C++ “undefine” module keyword in include

I'd like to use C++20 modules in visual studio, but one of my projects uses Magick++ which defines a struct with a member char* named "module" in "magick++.h": 我想在visual studio中使用C ++ 20模块,但我的一个项目使用Magick ++ ,它定义了一个带有成员char*struct ,在“magick ++。h”中命名为“module”:

 typedef struct _MagickInfo { char *name, *description, *version, *mime_type, *note, *module; /* offending member here */ /* ... other members ... */ } MagickInfo; 

Can I tell the compiler to not process "module" in that specific #include? 我可以告诉编译器不要在特定的#include中处理“模块”吗?

module isn't a keyword (you can find the list of keywords in [lex.key] and verify that it isn't there). module不是关键字(您可以在[lex.key]中找到关键字列表并验证它不存在)。

Instead, it's an "identifier with special meaning" ( [lex.name]/2 ), more commonly referred to as a context-sensitive keyword . 相反,它是“具有特殊含义的标识符”( [lex.name] / 2 ),通常称为上下文相关关键字

That is, there are only certain places where the module "keyword" is intended to be used, since module declarations can't appear everywhere. 也就是说,只有某些地方可以使用module “关键字”,因为模块声明不会出现在任何地方。 It's only those specific places that are going to be treated as module declarations. 只有那些特定的地方才会被视为模块声明。 For a more thorough treatment of how the compiler might do this disambiguation, see P0924 . 有关编译器如何消除歧义的更全面的处理,请参阅P0924

One of the motivations for making module (and import ) context-sensitive is that module is actually a fairly commonly used identifier in code - it's not just Magick++, there's also Vulkan . 使module (和import )上下文敏感的动机之一是module实际上是代码中相当常用的标识符 - 它不仅仅是Magick ++,还有Vulkan


In short, the fact that you have a type with a member named module isn't going to cause problems. 简而言之,您拥有名为module的成员类型的事实不会导致问题。 Having a type named module is worse (worse still if you have a global variable of that type - that could cause problems, but it would at least be possible to rewrite your code in such a way as to disambiguate the use of module in those situations). 拥有一个名为module类型更糟糕(更糟糕的是,如果你有一个这种类型的全局变量 - 可能会导致问题,但至少可以重写你的代码,以便在这些情况下消除module的使用歧义)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM