[英]understanding some source code
gcc 4.7.2
c89
你好,
我正在审查某人的源代码,并且遇到了这个问题。
我有这个声明和定义,我不明白它的作用。 我知道静态意味着它将不会从文件中导出。
static SERVICE_STATUS_HANDLE g_win_status_handle = NULL;
由于将其设置为NULL,因此它看起来像一个指针。 “ SERVICE_STATUS_HANDLE”在其他任何地方均未定义。 仅此文件。
它是这样使用的,是否在SERVICE_STATUS_HANDLE强制转换为0或NULL之后比较g_win_status_handle是否等于NULL:
if(g_win_status_handle == (SERVICE_STATUS_HANDLE)0) {
/* do something */
}
像这样:
if(!SetServiceStatus(g_win_status_handle, &g_win_status)) {
/* do something */
}
非常感谢有人能对此有所启示。
我做了小程序
#include<stdio.h>
static SERVICE_STATUS_HANDLE g_win_status_handle = NULL;
int main()
{
if(g_win_status_handle == (SERVICE_STATUS_HANDLE)0) {
printf("ksdfbhdejkfb");
}
return 0;
}
在gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
上gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
带有c89标志,例如
gcc -std=c89 temp.c
其给予错误
temp.c:3:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_win_status_handle’
temp.c: In function ‘main’:
temp.c:6:4: error: ‘g_win_status_handle’ undeclared (first use in this function)
temp.c:6:4: note: each undeclared identifier is reported only once for each function it appears in
temp.c:6:28: error: ‘SERVICE_STATUS_HANDLE’ undeclared (first use in this function)
temp.c:6:50: error: expected ‘)’ before numeric constant
在这里很明显,SERVICE_STATUS_HANDLE必须在某些位置定义。如果未定义,那么代码将如何编译?
可能是在某些头文件中定义的。
更新了评论的答案
SERVICE_STATUS_HANDLE
被定义windows.h
和它要包括。
http://msdn.microsoft.com/zh-CN/library/windows/desktop/aa383751%28v=vs.85%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.