{"id":9670,"date":"2018-02-10T15:15:34","date_gmt":"2018-02-10T14:15:34","guid":{"rendered":"http:\/\/blog.wenzlaff.de\/?p=9670"},"modified":"2018-08-17T17:26:25","modified_gmt":"2018-08-17T15:26:25","slug":"beautify-cc-code-mit-clang-format","status":"publish","type":"post","link":"http:\/\/blog.wenzlaff.de\/?p=9670","title":{"rendered":"Sch\u00f6ner C\/C++ Code mit clang-format in 10 Minuten"},"content":{"rendered":"<p>Wie kann C\/C++\/Java &#8230; Quellcode auf dem Raspberry Pi headless <strong>formatiert<\/strong> und h\u00fcbscher gemacht werden. Mit dem clang-format Programm das auch in Visual Studio, Emacs, Vim ua. Programme integriert werden kann. Das ist auch in Projekten sehr wichtig, um gleiche formatierungen f\u00fcr alle Projektmitglieder zu nutzen. Auch klappt es dann besser mit dem compare!<\/p>\n<p><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/02\/Clang-format.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/02\/Clang-format.png\" alt=\"\" width=\"2732\" height=\"2048\" class=\"aligncenter size-full wp-image-9675\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/02\/Clang-format.png 2732w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/02\/Clang-format-300x225.png 300w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/02\/Clang-format-768x576.png 768w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/02\/Clang-format-1024x768.png 1024w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<p>Das ist schnell installiert mit:<\/p>\n<pre class=\"lang:default decode:true \" >\r\n\r\nsudo apt-get install clang-format\r\n\r\n# Test ob es l\u00e4uft und in welcher Version\r\nclang-format -version\r\n# Ergebnis:\r\n# clang-format version 3.8.1-24+rpi1 (tags\/RELEASE_381\/final)\r\n\r\n# Aufruf mit Ausgabe \u00fcber Konsole, wir formatieren im Google Style m\u00f6glich w\u00e4hre aber auch noc\r\n# LLVM, Chromium, Mozilla, WebKit:\r\nclang-format -style=Google programm-4.cpp\r\n\r\n# Aufruf mit Ausgbe in neue Datei:\r\nclang-format -style=Google programm-4.cpp &gt; programm-4-format.cpp\r\n\r\n# Aufruf mit Ausgbe in der gleichen Datei, der wohl h\u00e4ufigste Anwendungsfall:\r\nclang-format -style=Google -i programm-4.cpp\r\n<\/pre>\n<p>Ok, dann noch hier die ganze Anleitung:<!--more--><\/p>\n<pre class=\"lang:default decode:true \" >OVERVIEW: A tool to format C\/C++\/Java\/JavaScript\/Objective-C\/Protobuf code.\r\n\r\nIf no arguments are specified, it formats the code from standard input\r\nand writes the result to the standard output.\r\nIf &lt;file&gt;s are given, it reformats the files. If -i is specified\r\ntogether with &lt;file&gt;s, the files are edited in-place. Otherwise, the\r\nresult is written to the standard output.\r\n\r\nUSAGE: clang-format [options] [&lt;file&gt; ...]\r\n\r\nOPTIONS:\r\n  -assume-filename=&lt;string&gt; - When reading from stdin, clang-format assumes this\r\n                              filename to look for a style config file (with\r\n                              -style=file) and to determine the language.\r\n  -cursor=&lt;uint&gt;            - The position of the cursor when invoking\r\n                              clang-format from an editor integration\r\n  -dump-config              - Dump configuration options to stdout and exit.\r\n                              Can be used with -style option.\r\n  -fallback-style=&lt;string&gt;  - The name of the predefined style used as a\r\n                              fallback in case clang-format is invoked with\r\n                              -style=file, but can not find the .clang-format\r\n                              file to use.\r\n                              Use -fallback-style=none to skip formatting.\r\n  -help                     - Display available options (-help-hidden for more)\r\n  -i                        - Inplace edit &lt;file&gt;s, if specified.\r\n  -length=&lt;uint&gt;            - Format a range of this length (in bytes).\r\n                              Multiple ranges can be formatted by specifying\r\n                              several -offset and -length pairs.\r\n                              When only a single -offset is specified without\r\n                              -length, clang-format will format up to the end\r\n                              of the file.\r\n                              Can only be used with one input file.\r\n  -lines=&lt;string&gt;           - &lt;start line&gt;:&lt;end line&gt; - format a range of\r\n                              lines (both 1-based).\r\n                              Multiple ranges can be formatted by specifying\r\n                              several -lines arguments.\r\n                              Can't be used with -offset and -length.\r\n                              Can only be used with one input file.\r\n  -offset=&lt;uint&gt;            - Format a range starting at this byte offset.\r\n                              Multiple ranges can be formatted by specifying\r\n                              several -offset and -length pairs.\r\n                              Can only be used with one input file.\r\n  -output-replacements-xml  - Output replacements as XML.\r\n  -sort-includes            - If set, overrides the include sorting behavior determined by the SortIncludes style flag\r\n  -style=&lt;string&gt;           - Coding style, currently supports:\r\n                                LLVM, Google, Chromium, Mozilla, WebKit.\r\n                              Use -style=file to load style configuration from\r\n                              .clang-format file located in one of the parent\r\n                              directories of the source file (or current\r\n                              directory for stdin).\r\n                              Use -style=\"{key: value, ...}\" to set specific\r\n                              parameters, e.g.:\r\n                                -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"\r\n  -version                  - Display the version of this program\r\n<\/pre>\n<p>Es gibt auch einige <a href=\"https:\/\/zed0.co.uk\/clang-format-configurator\/\" rel=\"noopener\" target=\"_blank\">Online Formatter<\/a> um die Formatierung im Browser durchzuf\u00fchren.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wie kann C\/C++\/Java &#8230; Quellcode auf dem Raspberry Pi headless formatiert und h\u00fcbscher gemacht werden. Mit dem clang-format Programm das auch in Visual Studio, Emacs, Vim ua. Programme integriert werden kann. Das ist auch in Projekten sehr wichtig, um gleiche formatierungen f\u00fcr alle Projektmitglieder zu nutzen. Auch klappt es dann besser mit dem compare! Das &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/blog.wenzlaff.de\/?p=9670\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eSch\u00f6ner C\/C++ Code mit clang-format in 10 Minuten\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[220,2874,3107,79,1023,7],"tags":[2741,3145,2872,3127,517,3146],"class_list":["post-9670","post","type-post","status-publish","format-standard","hentry","category-anleitung","category-c","category-c-programmierung","category-programmierung","category-raspberry-pi","category-tools","tag-c","tag-clang-format","tag-cpp","tag-formater","tag-quellcode","tag-schoener"],"_links":{"self":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/9670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9670"}],"version-history":[{"count":0,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/9670\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9670"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}