无法访问 C 中的 #define 常量
这是我正在使用的一个C程序,在头文件中我定义了一个偏移量:
#define LDR_DATA_PATHFILENAME_OFFSET 0x24 // MODULE_ITEM.PathFileName
稍后在程序中我使用它如下:
pImageName = (PUNICODE_STRING)( ((DWORD)(pUserModuleListPtr)) +
(LDR_DATA_PATHFILENAME_OFFSET-dwOffset));
当检查LDR的值时,我得到一个CXX0017:错误:符号“LDR_DATA_PATHFILENAME_OFFSET”不是找到了。 嗯,它已定义,它已编译,但它无法访问该值! 我究竟做错了什么?
This is a C program that I was using, in the header file I define an offset:
#define LDR_DATA_PATHFILENAME_OFFSET 0x24 // MODULE_ITEM.PathFileName
Later in the program I use it as following:
pImageName = (PUNICODE_STRING)( ((DWORD)(pUserModuleListPtr)) +
(LDR_DATA_PATHFILENAME_OFFSET-dwOffset));
When inspecting the value of LDR i get an CXX0017: Error: symbol "LDR_DATA_PATHFILENAME_OFFSET" not found. Erm, its defined, it compiles, but yet it can't access the value! What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我假设您正在调试您的应用程序,因为您说“检查”:符号常量在编译时被其值替换。 在运行时你再也看不到它们了。
I am assuming that you are debugging your application because you said "inspecting": Symbolic constants are substituted by its values at compile time. At runtime you can´t see them anymore.
你确定你的头文件被包含了吗?
轻松检查 - 将 #define 从头文件复制粘贴到 C 文件的开头。
仔细检查头文件中的 #ifndef 防护。
Are you sure your header file is being included?
Easy check - copypaste the #define from the header file to the beginning of your C file.
Double check the #ifndef guards in your header file.
在编译器中找到转储预处理源的选项,以便您可以看到到底发生了什么。 您的符号可能未定义,或者您的标头未按您的预期正确包含。
Find the option in your compiler to dump preprocessed source so you can see what's really going on. Your symbol may have gotten undefined, or your header isn't included correctly as you expect.
您使用的是较旧的 C 编译器吗? 您使用的是 C++ 风格注释 // 而不是 C 风格注释 /* */。 较旧的 C 编译器无法识别 //。
Are you using an older C compiler? You're using a C++ style comment // instead of the C style comment of /* */. Older C compilers won't recognize the //.