Checking a value defined in a header from a function in another file
I have a header file (head.h) in which I define the boolean value:
bool flag = false;
In main.c, I have a function:
void WINAPI function (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
if (flag == false)
{
//Some action
flag =开发者_运维问答 true;
}
}
The boolean value 'flag' is not recognised even though main.c starts with the line:
#include "head.h"
...Why?
I believe you put #include "head.h"
at the top of main.c
(before #include "stdafx.h"
) and you use precompiled header(at least it's how I'm able to reproduce your issue with Visual Studio). #include "stdafx.h"
should always go first .
What do you mean by "not recognized"? Does it fail to compile saying flag
isn't defined?
Otherwise, in the code you exhibit, there is a little problem that flag has never been set.
精彩评论