【问题标题】:Lint Warning Expected positive indentation棉绒警告预期的正缩进
【发布时间】:2018-12-12 09:51:08
【问题描述】:

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

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
}
}

谢谢!

【问题讨论】:

  • 这还能编译吗?
  • 假设这是一个例子,我修复了明显的错误。
  • @PaulOgilvie:但同时您删除了lint 警告的问题!
  • @usr2564301,我不想将代码复制到我的答案中。
  • @PaulOgilvie:好吧,为什么不呢,如果它让你的答案更清楚。但是编辑被问到的问题是绝对不行的。

标签: c for-loop lint


【解决方案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 抱怨您没有正确遵守缩进规则。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2013-11-02
    • 1970-01-01
    相关资源
    最近更新 更多