Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 1023 Bytes

clang-format.md

File metadata and controls

45 lines (33 loc) · 1023 Bytes

clang-format

  1. A basic configuration file for C/C++ files

    File .clang-format, put it at the root dir of source code:

    BasedOnStyle: LLVM
    IndentWidth: 4
    BreakBeforeBraces: Linux
    AllowShortIfStatementsOnASingleLine: false
    IndentCaseLabels: true

    Run:

    # apply to specific file, -i: inplace edit
    $ clang-format -i test.c
    
    # apply to source directory, recursivly
    $ clang-format -i .
    
    # apply to only .c files
    $ find . -name '*.c' | xargs clang-format -i

    .clang-format for 3.5

  2. clang-format off for a piece of code

    // clang-format off or /* clang-format off */ in source code could be understood by clang-format:

    int formatted_code;
    // clang-format off
        void    unformatted_code  ;
    // clang-format on
    void formatted_code_again;

References

  1. CLANG-FORMAT STYLE OPTIONS