如何抑制#define本地? [英] How to suppress #define locally?
问题描述
刚刚抓到一个蠢的bug。我有一个带有 CreateFile()
函数的zip处理库。 Winbase.h
,包含在我的头部深处,重新定义为 CreateFileW
当然,在这种情况下,我将排除 winbase
。它只是不应该在范围内的第一位。但是理论问题仍然很有趣,
有没有办法抑制一些本地定义?
删除令人讨厌的头文件是最好的解决方案(特别是 windows.h
或 .h
- 它们包含的太多了,我的口味在许多项目)。
唯一的其他解决方案是 #undef offending_symbol
。
当然,另一个重要的事情是不要使用匹配Windows / Linux系统调用名称的名称 - 但 CreateFile
是一个非常明显的名称,一个文件,所以我可以看到诱惑。
Just caught a silly bug. I have a zip processing library with a CreateFile()
function in it. Winbase.h
, included somewhere deep in my headers, redefines it as CreateFileW
and linker goes nuts.
Of course I will exclude winbase
in this particular case. It just shouldn't be in the scope in the first place. But the theoretical question is still interesting,
Is there a way to suppress some defines locally?
Removing the offending header file is ALWAYS the best solution for this (especially one as large as windows.h
or winbase.h
- they are included far too freely for my taste in many projects).
The only other solution is #undef offending_symbol
.
Of course, another important thing is "do not use names that match the Windows/Linux system call names" - but CreateFile
is a very obvious name for a function that creates a file, so I can see the temptation.
这篇关于如何抑制#define本地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!