5个 .indent.pro C语言配置文件示例:K&R、GNU、Allman、Whitesmiths、Google

.indent.pro是一款用于代码格式化的工具,能够根据配置文件自动格式化代码缩进、空格等。本文推荐5个常用的.indent.pro配置文件,分别对应K&R、GNU、Allman、Whitesmiths和Google风格的C语言代码缩进方式,并提供示例代码帮助理解。

1. K&R 风格

该配置文件使用了K&R风格的缩进方式,即花括号独占一行,且缩进量为4个空格。

# K&R style
-indent-level4
-le4
-bad

示例代码:

#include <stdio.h>

int main()
{
    int a = 1;
    if (a == 1)
    {
        printf('Hello, world!\n');
    }
    else
    {
        printf('Goodbye, world!\n');
    }
    return 0;
}

2. GNU 风格

该配置文件使用了GNU风格的缩进方式,即花括号与前面的语句放在同一行,并且缩进量为2个空格。

# GNU style
-gnu
-indent-level2
-le2

示例代码:

#include <stdio.h>

int main()
{
  int a = 1;
  if (a == 1) {
    printf('Hello, world!\n');
  } else {
    printf('Goodbye, world!\n');
  }
  return 0;
}

3. Allman 风格

该配置文件使用了Allman风格的缩进方式,即花括号独占一行,并且缩进量为4个空格。

# Allman style
-style=allman
-indent-level4
-le4

示例代码:

#include <stdio.h>

int main()
{
    int a = 1;
    if (a == 1)
    {
        printf('Hello, world!\n');
    }
    else
    {
        printf('Goodbye, world!\n');
    }
    return 0;
}

4. Whitesmiths 风格

该配置文件使用了Whitesmiths风格的缩进方式,即花括号独占一行,并且缩进量为2个空格。

# Whitesmiths style
-style=whitesmiths
-indent-level2
-le2

示例代码:

#include <stdio.h>

int main()
{
  int a = 1;
  if (a == 1)
    {
      printf('Hello, world!\n');
    }
  else
    {
      printf('Goodbye, world!\n');
    }
  return 0;
}

5. Google 风格

该配置文件使用了Google风格的缩进方式,即花括号与前面的语句放在同一行,并且缩进量为2个空格。

# Google style
-style=google
-indent-level2
-le2

示例代码:

#include <stdio.h>

int main() {
  int a = 1;
  if (a == 1) {
    printf('Hello, world!\n');
  } else {
    printf('Goodbye, world!\n');
  }
  return 0;
}
5个 .indent.pro C语言配置文件示例:K&R、GNU、Allman、Whitesmiths、Google

原文地址: https://www.cveoy.top/t/topic/nsPP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录