【问题标题】:Passed-by-value struct argument contains uninitialized data按值传递的结构参数包含未初始化的数据
【发布时间】:2013-10-29 21:04:52
【问题描述】:

我在下面的代码部分中收到以下“按值传递的结构参数包含未初始化的数据”:

for ( int i = 0; i < 48; i++ )
{

    CGPoint posLevel;
    LevelButton* pBtn;
    if ( i >= 0 && i < 24 )
    {
        int nXX = (i % 4 + 1);

        if ( i < [pBtnArray count] )
        {
            posLevel = ccp( (spMask.position.x - mySize.width / 2) + mySize.width / 5 * nXX, 
                           mySize.height - mySize.height / 7 * (i / 4 + 1));
            pBtn = [pBtnArray objectAtIndex:i];
            if ( pBtn != nil )
            {
                [pBtn move:posLevel];
            }

        }

    }

用xcode添加的箭头,这些有帮助吗??

一旦注释掉的代码被删除,这里就没有太多代码了,所以我不明白 XCode 抛出的问题是什么。

如果能帮助您消除此错误,我们将不胜感激!

【问题讨论】:

    标签: ios objective-c xcode cocos2d-iphone


    【解决方案1】:

    你截图中的代码是这样的

    CGRect posLevel;
    if (mySize.height < 568) {
        posLevel = ...;
    }
    if (mySize.height >= 568) {
        posLevel = ...;
    }
    [pBtn move:posLevel];
    

    似乎静态分析器无法识别第一个 或者在任何情况下都执行第二个 if 块。 蓝色箭头表示两个 if 块都执行的流程, 在这种情况下,posLevel 将是未定义的。

    你可以使用 if-else 来解决这个问题:

    CGRect posLevel;
    if (mySize.height < 568) {
        posLevel = ...;
    } else {
        posLevel = ...;
    }
    [pBtn move:posLevel];
    

    【讨论】:

      猜你喜欢
      • 2020-05-28
      • 2015-05-04
      • 1970-01-01
      • 2018-08-11
      • 2022-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多