The configurator gives you a list of styles you can choose from for this option. Note that using the right BasedOnStyle entry helps keep the configuration to a minimum. In the case of the xsimd project, we ended up with the following: Once you've found the style you like, the configurator will dump the associated configuration for you. This web application makes it possible to interactively explore different styling options and watch their impact on a codebase. clang-format file, you can use the clang-format configurator. Instead of walking through all the different formatting directives that might go into a. Only then does it fall back to the default LLVM style.Īmong other settings, clang-format can normalize the spacing before and after commas, positioning of brackets, alignments of arguments, and the maximum column width. clang-format file in the current folder if it cannot find one, it goes up one level in the directory tree and looks there, repeating the process until it finds one or reaches the root directory ( /). The default style is the one used by the LLVM project itself, but you can provide your own style guide in the form of a. Omitting -i dumps the indented content on the standard output instead of modifying the input in place. You can run the tool like this:Įxecuting this command will format my/source/file.cpp according to the default style. Introducing clang-formatĬlang-format is a tool that auto-formats C, C++, and Objective C, much as the venerable indent tool does for C. Note that clang-format is part of the LLVM project. I will show you how to choose a code style, convert an existing codebase to that new style, and enforce the code style on future commits. This article introduces clang-format, an uncomplicated tool that you can use to set a common code style for your team projects written C, C++, and Objective C.Īs an example for our discussion, I'll use xsimd, a project I contribute to, which enables the manipulation of batches of numbers with the same arithmetic operators used for single values. Code styling can also be especially challenging in open source projects because different contributors have their own style preferences. Code consistency is particularly important in open source projects, where contributors often revise code written by others. Imposing a common coding style can improve the readability and maintainability of your code in shared projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |