You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于GNU indent(2.2.12)在void函数体后不添加空行是否为Bug的技术问询

Is this a bug in GNU indent 2.2.12?

Yes, this absolutely looks like a bug in GNU indent 2.2.12, specifically tied to how it processes void functions without an explicit return statement when using the Kernighan & Ritchie (-kr) formatting style.

Let's break down what's happening here:

  1. The problematic case
    When you run this command:

    $ echo 'void B(int *b) { *b += 2; } void C(int *c) { *c += 3; }' | indent -kr
    

    You get this unformatted output (no blank line between functions):

    void B(int *b) { *b += 2; } void C(int *c) { *c += 3; }

    This is clearly wrong—indent -kr is supposed to insert a blank line between top-level functions, per K&R style conventions.

  2. The working case
    Add an explicit return; to the void function, and suddenly it works as expected:

    $ echo 'void B(int *b) { *b += 2; return; } void C(int *c) { *c += 3; }' | indent -kr
    

    Output:

    void B(int *b) { *b += 2; return; }
    void C(int *c) { *c += 3; }

What's causing this?

It seems like the indent parser in 2.2.12 is relying on the presence of a return statement (even a void one) to correctly detect the end of a function. Without that explicit return, it fails to recognize that the closing } of B() marks the end of the function body, so it doesn't insert the required blank line before C().

This is inconsistent behavior—void functions don't require an explicit return in C, and indent should handle both cases uniformly for the -kr style.

Fix options

If you can, upgrading to a newer version of GNU indent (2.2.13 or later) resolves this issue. The bug was addressed in subsequent releases to properly parse function boundaries regardless of whether a void function has an explicit return.

内容的提问来源于stack exchange,提问作者uncleremus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 08:12:30