Programming Tips - clang-format: how to run it

Date: 2020jul8 Language: C/C++ Keywords: auto-format your code Q. clang-format: how to run it A. If you want to use the Google C++ Style: https://google.github.io/styleguide/cppguide.html
clang-format -style '{BasedOnStyle: Google, DerivePointerBinding: false, Standard: Cpp11}'
Where myfile.cpp is your file to be formatted. And myfile_fmt.cpp is your file after its been re-formatted. Of course there are other style options. See
clang-format --help
for more info. I made a small script to run it:
#!/bin/sh if [[ $# -ne 2 ]]; then echo "Usage: cfmt <in-cpp-file> <out-cpp-file>" exit 1 fi INFILE=$1 OUTFILE=$2 STYLE='{BasedOnStyle: Google, DerivePointerBinding: false, Standard: Cpp11}' clang-format -style "$STYLE" $INFILE > $OUTFILE