Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add a style based on the GNU coding conventions #18225

Closed
dnovillo opened this issue Nov 8, 2013 · 2 comments
Closed

Please add a style based on the GNU coding conventions #18225

dnovillo opened this issue Nov 8, 2013 · 2 comments
Labels
bugzilla clang-format

Comments

@dnovillo
Copy link
Contributor

@dnovillo dnovillo commented Nov 8, 2013

Bugzilla Link 17851
Resolution FIXED
Resolved on Aug 05, 2014 07:20
Version unspecified
OS All

Extended Description

Would it be possible to add a GNU coding style? The full style description for the GNU coding conventions is at http://www.gnu.org/prep/standards/standards.html#Writing-C.

Out of those conventions, I think these are the more prominent ones:

  • Line length is 80 columns.

  • Open brace for a function body is always in column 1.

  • The name of the function is always at column 1.
    The above two rules mean that function definition 'int foo(int x, int y) { ... }' must be formatted as:

int
foo (int x, int y)
{
...
}

  • There must always be a space between a function name and the open parens. So, it's "foo (x, y)", never "foo(x, y)". Yeah, I hate it too.

  • Open braces for structs/unions can be on the same line or column 1.

  • There is always a space after a comma.

  • Braces always go on the next line, indented by 2:

int
foo (int x, int y)
{
while (x < y)
{
do_something_with (x);
x++;
}
return x;
}

  • When splitting expressions into multiple lines, split BEFORE the operator:

    if (this_is_a_very_long_predicate
    && x > this_other_value)
    {
    ...
    }

  • do-while statements are formatted like:

    do
    {
    ...
    }
    while (...);

Thanks.

@llvmbot
Copy link
Collaborator

@llvmbot llvmbot commented Dec 16, 2013

Starting from r197138 clang-format supports most of GNU style conventions. You can try this using -style=gnu or putting "BasedOnStyle: GNU" in your project's .clang-format file.

At the moment, there are at least two unsupported features:

  • always breaking before function names;
  • formatting of pre-standard C function argument lists: void f (a, b) int a, char b;

The absence of the former feature doesn't allow to format whole files, but you can still format function bodies using the editor integration. I don't know how much we care about the latter.

Please report, what other features would you like to be implemented for the GNU style support to be usable.

@llvmbot
Copy link
Collaborator

@llvmbot llvmbot commented Aug 5, 2014

Function return types are now forced on their own line in GNU style (r214858).

I'll mark this as fixed. Please reopen individual bug reports if you find missing features. Or reopen this one if the pre-standard C function argument lists are important (I can't really judge that).

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla clang-format
Projects
None yet
Development

No branches or pull requests

2 participants