2

Look at the formatting of the variable declarations. I haven't encountered this indentation style in the past, but lately I stumbled upon two different code examples which use this style. Where does it come from? Is it still used today?

#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>

void __cdecl odprintf(const char *format, ...)
{
char    buf[4096], *p = buf;
va_list args;
int     n;

        va_start(args, format);
        n = _vsnprintf(p, sizeof buf - 3, format, args); // buf-3 is room for CR/LF/NUL
        va_end(args);

        p += (n < 0) ? sizeof buf - 3 : n;

        while ( p > buf  &&  isspace(p[-1]) )
                *--p = '\0';

        *p++ = '\r';
        *p++ = '\n';
        *p   = '\0';

        OutputDebugString(buf);
}

©

1
  • It may be just someone's personal preference. I used to write some (Object) Pascal using 3-space indentation just because I thought it looked good.
    – scriptin
    Feb 27, 2015 at 20:22

1 Answer 1

4

This is a variation on the kernel style or Allman style with the modification of variables within the block are outdented to the level of the open brace to set them clearly apart from the code that follows.

This also superficially resembles aspects of early C dialects where the parameters and types are declared outside the code block rather than in the code block:

int f(x)
int x;
{
    return x + 1;
}

There are nearly as many indent styles as there are programmers. Occasionally two programmers might agree on a style within a project. Sometimes they borrow elements of someone else's code style and use that.

This is just another personal choice for indent style. Move along.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.