Sample Header Ad - 728x90

Why does GNU Indent collapse one level of indentation?

2 votes
1 answer
381 views
When I try to format my C code using [GNU Indent](https://www.gnu.org/software/indent/) , it doesn't seem to deal with multiple levels of nested indentation. Specifically, it seems to collapse the second level of indentation. For example, if this is the code I start with:
#include 

int main(int argc, char *argv[])
{
    int n;

    if (argc > 1) {
        printf("# of args: %d\n", argc);
    }

    for (n = 1; n 

int main(int argc, char *argv[])
{
    int n;

    if (argc > 1) {
	printf("# of args: %d\n", argc);
    }

    for (n = 1; n 

int
main (int argc, char *argv[])
{
  int n;

  if (argc > 1)
    {
      printf ("# of args: %d\n", argc);
    }

  for (n = 1; n <= 15; n++)
    {
      if (n % 3 == 0)
	{
	  printf ("fizz %d\n", n);
	}
      else if (n % 5 == 0)
	{
	  printf ("buzz %d\n", n);
	}
      else if (n % 3 == 0 && n % 5 == 0)
	{
	  printf ("fizzbuzz %d\n", n);
	}
      else
	{
	  printf ("%d\n", n);
	}
    }

  return 0;
}
Seems like if it does this out-of-the-box, lots of people would be asking about it, because if it's not a bug, it seems like a really strange way to format your code. Why does it do this? I'm using version 2.2.11 of GNU Indent.
Asked by jnrbsn (189 rep)
Jan 18, 2019, 08:26 PM
Last activity: Jan 18, 2019, 09:40 PM