====== C Coding Guidelines ====== * Coding for Reviewability * [[performance]] * [[portability]] ===== Standards ===== * [[..:misra-c]] * [[https://www.securecoding.cert.org/confluence/display/c/SEI+CERT+C+Coding+Standard|CERT C Coding Standards]] ===== Best Practice ===== The general rule is to maximize readability, not minimize typing.\\ — CuriousRabbit, [[http://stackoverflow.com/users/452979/curiousrabbit]] * [[https://blog.codinghorror.com/a-pragmatic-quick-reference/|The Pragmatic Programmer Quick Reference Guide]] [(https://web.archive.org/web/20190523125347/https://blog.codinghorror.com/a-pragmatic-quick-reference/)] -- Fundamentals * [[https://www.gnu.org/prep/standards/standards.html|GNU Coding Standards]] [(https://web.archive.org/web/20190312025600/https://www.gnu.org/prep/standards/standards.html)] * [[https://users.ece.cmu.edu/~eno/coding/CCodingStandard.html|C Coding Standard]] [(https://web.archive.org/web/20190329082321/https://users.ece.cmu.edu/~eno/coding/CCodingStandard.html)] * {{http://www.ostc.de/crules.pdf|C-Programmier-Konventionen, Tipps und Werkzeuge}} [(https://web.archive.org/web/20190329082415/http://www.ostc.de/crules.pdf)] * {{http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf|JPL Institutional Coding Standard for the C Programming Language}} * {{http://www.maultech.com/chrislott/resources/cstyle/Peter_CStyleGuide.pdf|‘C’ Style Guide and Programming Guidelines}} * [[http://www.tty1.net/c_coding_guideline_en.html|A modern "C" coding guideline]] * [[http://www.barrgroup.com/Embedded-Systems/How-To/Bug-Killing-Standards-for-Embedded-C|Bug-Killing Coding Standard Rules for Embedded C]] * [[http://www.fast-product-development.com/safe-c.html#top_safe_c_guidelines|Safe C Guidelines for Embedded Systems]] * Use [[https://en.wikipedia.org/wiki/Include_guard|#include guard]] for your C Header files. * [[https://embeddedgurus.com/barr-code/2011/08/dont-follow-these-5-dangerous-coding-standard-rules/|Don’t Follow These 5 Dangerous Coding Standard Rules]] [(https://web.archive.org/web/20190329112315/https://embeddedgurus.com/barr-code/2011/08/dont-follow-these-5-dangerous-coding-standard-rules/)] * {{https://www.exida.com/images/uploads/exida_C_C++_Coding_Standard_-_IEC61508.pdf|C/C++ Coding Standard Recommendations for IEC 61508}} [(https://web.archive.org/web/20190805065328/https://www.exida.com/images/uploads/exida_C_C++_Coding_Standard_-_IEC61508.pdf)] ~~REFNOTES~~ ===== Examples ===== * http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style?rev=1.45&content-type=text/plain [(https://web.archive.org/web/20190329082136/http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style?rev=1.45&content-type=text/plain)] ~~REFNOTES~~ ===== Diskussion ===== * [[http://embeddedgurus.com/stack-overflow/2013/02/whats-in-your-main-header|What’s in your main() header?]] * [[http://embeddedgurus.com/stack-overflow/2013/04/idling-along|Idling along, (or what to do in the idle task)]] * [[http://embeddedgurus.com/stack-overflow/2013/01/real-world-variables/|Real world variables]] * [[http://www.barrgroup.com/Embedded-Systems/How-To/C-Fixed-Width-Integers-C99|Portable Fixed-Width Integers in C]] * [[http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/|Efficient C Tips #1 – Choosing the correct integer size]] * [[http://embeddedgurus.com/barr-code/2011/06/is-uint16_t-1-portable-c-code/|Is “(uint16_t) -1″ Portable C Code?]] * [[http://embeddedgurus.com/barr-code/2010/11/what-belongs-in-a-c-h-header-file/|What Belongs in a C .h Header File?]] * [[http://embeddedgurus.com/barr-code/2011/03/do-inline-function-bodies-belong-in-c-header-files/|Do Inline Function Bodies Belong in C Header Files?]] * [[http://embeddedgurus.com/stack-overflow/2010/11/configuring-hardware-part-1/|Configuring hardware – part 1]] * [[http://embeddedgurus.com/stack-overflow/2010/12/configuring-hardware-%E2%80%93-part-2/|Configuring hardware – part 2]] * [[http://embeddedgurus.com/stack-overflow/2011/01/configuring-hardware-part-3/|Configuring hardware – part 3]] * [[http://www.barrgroup.com/Embedded-Systems/How-To/Interrupt-Service-Routines|Minimize Interrupt Service Routine Overhead]] * [[http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline|Why should files end with a newline?]] * [[http://stackoverflow.com/questions/2287967/why-is-it-recommended-to-have-empty-line-in-the-end-of-file|Why is it recommended to have empty line in the end of file?]] ==== Line Width ==== * [[https://stackoverflow.com/questions/276022/line-width-formatting-standard|Line width formatting standard]] [(https://web.archive.org/web/20190329110756/https://stackoverflow.com/questions/276022/line-width-formatting-standard)] * [[https://stackoverflow.com/questions/110928/is-there-a-valid-reason-for-enforcing-a-maximum-width-of-80-characters-in-a-code|Is there a valid reason for enforcing a maximum width of 80 characters in a code file, this day and age?]] [(https://web.archive.org/web/20190329111102/https://stackoverflow.com/questions/110928/is-there-a-valid-reason-for-enforcing-a-maximum-width-of-80-characters-in-a-code)] ~~REFNOTES~~ ===== Recommended Reading ===== * [[https://blog.codinghorror.com/a-pragmatic-quick-reference/|A Pragmatic Quick Reference]] -- //www.codinghorror.com // * //Dr. Stephan Grünfelder und Franz Griesauer// -- Guter Code braucht Ordnung * {{http://www.elektrowiki.de/mirror/nonfree/magazines/elektronik/Guter Code braucht Ordnung/200118s052.pdf|Teil 1: Universelle Regeln zur Namensgebung und zu Zahlenformaten in Programmiersprachen}} -- Artikel, Elektronik 18/2001 * {{http://www.elektrowiki.de/mirror/nonfree/magazines/elektronik/Guter Code braucht Ordnung/200208s074.pdf|Teil 2: Das Code-Layout - Übersichtliches Aussehen macht Code besser erfassbar}} -- Artikel, Elektronik 8/2002 * {{http://www.elektrowiki.de/mirror/nonfree/magazines/elektronik/Guter Code braucht Ordnung/200214s066.pdf|Teil 3: Fehlervermeidung bei der Erstellung von C-Programmen}} -- Artikel, Elektronik 14/2002 * {{http://www.stroustrup.com/JSF-AV-rules.pdf|Joint Strike Fighter Air Vehicle C++ Coding Standards}} * http://www.cs.swarthmore.edu/~newhall/unixhelp/c_codestyle.html * http://stackoverflow.com/questions/2627333/how-should-one-comment-an-if-else-structure