使用变量名时触发编译错误
我正在使用一个名为 Rational Rose for C++ 的工具。当定义包含单词“interface”的变量名称时,该工具将停止工作并打印出空白错误消息。
支持问题可以在这里看到: https://www-304.ibm.com/support /docview.wss?uid=swg21271841&wv=1
我想添加一个预处理器指令,以便当变量名称使用“interface”时,会显示编译错误。
大致如下:
#define interface #error The Keyword interface is not permitted
I am using a tool called Rational Rose for C++. When a variable name which includes the word "interface" is defined, the tool stops working and prints out a blank error message.
The support issue can be seen here:
https://www-304.ibm.com/support/docview.wss?uid=swg21271841&wv=1
I would like to add a preprocessor directive such that when the variable name "interface" is used, a compile error will be displayed.
Something along the lines of:
#define interface #error The Keyword interface is not permitted
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能在预处理器语句内使用预处理器语句。
但是,您可以按照以下方式强制编译器错误:
在 Windows(MS 编译器)上,这会将您指向包含错误的代码行:
会同意这里的其他人,尽管这似乎是解决问题的错误位置。
编辑: 正如 DeadMG 所指出的,只有当您正在寻找精确的变量名称而不是部分匹配时,此解决方案才有效。
You can't use preprocessor statements inside preprocessor statements.
However, you can force a compiler error along these lines:
On windows (MS compiler) this would point you to the code line with the error:
Would agree with others here though that it seems to be the wrong place for a solution to your problem.
EDIT: As pointed out by DeadMG, this solution would only work if you're looking for exact variable names, rather than partial matches.
您不能使用预处理器来获得部分匹配。如果我编写
IInterface
和EInterface
和IlikeBigInterfacesAndICannotLie
,那么您无法使用预处理器来匹配它们。You can't use the preprocessor to gain partial matches. If I write
IInterface
andEInterface
andILikeBigInterfacesAndICannotLie
, then you cannot use the preprocessor to match them all.