为什么我的变量报告为"未声明的标识符"什么时候编译?

时间:2014-12-31 14:09:11

标签: c variables scope

我有以下代码:

       for(int iY=0;iY<(Height-YRemainder);iY=iY+16);
        {
            for(int iX=0;iX<(Width-XRemainder);iX=iX+16);
            {
                if(Operation==BLACKNESS)
                {
                    Operation = WHITENESS;
                    PatBlt(DeviceContext, iX, iY, 16, 16, Operation);
                }
                else
                {
                    Operation = BLACKNESS;
                    PatBlt(DeviceContext, iX, iY, 16, 16, Operation);
                }
            }
            if(Operation == BLACKNESS)
            {
                Operation = WHITENESS;
                PatBlt(DeviceContext, Width-XRemainder,iY,16,16,Operation);
            }
            else
            {
                Operation = BLACKNESS;
                PatBlt(DeviceContext, Width-XRemainder, iY, 16, 16, Operation);
            }


        }

当我编译时,我会针对iX和iY针对每个PatBlt报告未声明的标识符。我误解了每个变量的范围在这里是如何工作还是我错过了什么?

提前致谢

1 个答案:

答案 0 :(得分:3)

你在for语句的末尾有半冒号,它们将它们变成单行语句:

for(int iY=0;iY<(Height-YRemainder);iY=iY+16);

成为

for(int iY=0;iY<(Height-YRemainder);iY=iY+16)