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 [[ $# -lt 1 ]]; then echo "Usage: cfmt <cpp-files>" exit 1 fi FILES=$* STYLE='{BasedOnStyle: Google, DerivePointerBinding: false, Standard: Cpp11}' clang-format -style "$STYLE" -i $FILES