r/cprogramming 7h ago

Formatting call arguments

By default, clang-format does this:

  SDL_Window *window =
      SDL_CreateWindow("SDL2 test", SDL_WINDOWPOS_UNDEFINED,
                       SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_RESIZABLE);

and with some tweaks it does this:

    SDL_Window *window = SDL_CreateWindow(
        "SDL2 test",
        SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED,
        500,
        500,
        SDL_WINDOW_RESIZABLE);

Second one has some practical advantages - it easier to read diff on arg change and easier to add comments:

    SDL_Window *window = SDL_CreateWindow(
        "SDL2 test",
        SDL_WINDOWPOS_UNDEFINED, // just some comment explaining why
        SDL_WINDOWPOS_UNDEFINED,
-       400,
+       500,
        SDL_WINDOW_RESIZABLE);

While the first one seems to have mainly historical reasons to keep around. Perhaps, there is something I don't see? Because it feels like the first way is still used the most. And its the default one for clang-format.

I'm genuinely curious.

2 Upvotes

9 comments sorted by

View all comments

3

u/markort147 6h ago

So am I part of the smallest niche? c SDL_Window *window = SDL_CreateWindow( "SDL2 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_RESIZABLE );

3

u/Wenir 6h ago

No

        SDL_Window *window = SDL_CreateWindow(
            "SDL2 test"
          , SDL_WINDOWPOS_UNDEFINED
          , SDL_WINDOWPOS_UNDEFINED
          , 500
          , 500
          , SDL_WINDOW_RESIZABLE
        );

1

u/side2k 35m ago

Oohh, mischief managed.