棉绒警告预期为正压痕

时间:2018-12-12 09:51:09

标签: c for-loop lint

我有一个for循环,它根据数字(nr)将值分配给结构中的成员,但是当我尝试这段代码时,它会抱怨期望的正缩进那是什么意思?此代码段有什么问题

fun lint(U16 c, U16 d, U16 e, U16 nr)
{
struct* something[50]
for(U16 i=0; i<nr; i++) //Expected positive indentation
{
something[i] = alloc(sizeof(struct) *nr); //something[i] complains here
something[i] -> ab.c = c; //something[i] complains here
something[i] -> ab.d = d; //something[i] complains here
something[i] -> nrofthing = nr; //something[i] complains here
something[i] -> ab.e =e; //something[i] complains here
}
}

谢谢!

1 个答案:

答案 0 :(得分:1)

我已经“积极缩进您的代码”。那就是正确格式化的代码的样子:在每个代码块或循环中,缩进4个空格或1个制表符。

fun lint(U16 c, U16 d, U16 e, U16 nr)
{
    struct x *something[50];
    for(U16 i=0; i<nr; i++) //Expected positive indentation
    {
        something[i] = malloc(sizeof(struct x) *nr); //something[i] complains here
        something[i]->ab.c = c; //something[i] complains here
        something[i]->ab.d = d; //something[i] complains here
        something[i]->nrofthing = nr; //something[i] complains here
        something[i]->ab.e =e; //something[i] complains here
    }
}

有了这样的缩进,很容易看到块,函数和循环在哪里开始和结束,从而更容易阅读代码。

Lint抱怨您没有正确遵守缩进规则。

相关问题