开发者

Checking a value defined in a header from a function in another file

开发者 https://www.devze.com 2023-03-05 17:11 出处:网络
I have a header file (head.h) in which I define the boolean value: bool flag = false; In main.c, I have a function:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消