Coding standards are collections of coding rules, guidelines, and best practices. Using the right coding standards — such as C coding standards and C++ coding standards — will help you write cleaner code.
Here we explain why coding standards (such as C coding standards) and coding rules are important, so consider this your guide to finding and using coding standards, and coding standards rules and guidelines.
Read along or jump to the section that interests you most:
- What Are Coding Rules and Guidelines?
- Why Coding Standards Are Important?
- Important C Coding Standards
- Important C++ Coding Standards
- How to Enforce Coding Standards With Static Code Analysis
- ➡️ Start Your Free Static Code Analysis Trial
What Are C Coding Standards and Coding Rules and Guidelines?
Coding rules and guidelines ensure that software is:
- Safe: It can be used without causing harm.
- Secure: It can’t be hacked.
- Reliable: It functions as it should, every time.
- Testable: It can be tested at the code level.
- Maintainable: It can be maintained, even as your codebase grows.
- Portable: It works the same in every environment.
▶️ Related Webinar: How to Apply a Coding Standard
Why Are Coding Standards Important?
The reason why coding standards are important is that they help to ensure safety, security, and reliability.
Every development team should use one. Even the most experienced developer could introduce a coding defect — without realizing it. And that one defect could lead to a minor glitch. Or worse, a serious security breach.
There are four key benefits of using coding standards:
1. Compliance with industry standards (e.g., ISO).
2. Consistent code quality — no matter who writes the code.
3. Software security from the start.
4. Reduced development costs and accelerated time to market.
In embedded systems industries, these coding standards are required (or highly recommended) for compliance. This is especially true for functional safety standards, including:
- IEC 61508: “Functional safety of electrical/electronic/programmable electronic safety-related systems”
- ISO 26262: “Road vehicles — functional safety”
- EN 50128: “Railway applications — Communication, signaling, and processing systems — Software for railway control and protection systems”
- IEC 62061: "Safety of machinery: Functional safety of electrical, electronic and programmable electronic control systems"
Each one is written for a specific programming language. Most embedded systems developers use C or C++.
Important C Coding Standards
The C programming language is flexible. It’s also known for high performance. That’s why it’s popular among embedded developers.
But C is also prone to risk. C code can be compiled with undefined behavior. And that undefined behavior opens your code up to vulnerabilities and defects. Or your C code may be unpredictable when it’s ported to different hardware.
Using C coding standards is a smart way to find undefined and unpredictable behaviors.
There are several established standards. Some are specifically designed for functional safety — such as MISRA. Others are focused on secure coding, including CERT.
Popular Embedded C Coding Standards
Learn more about MISRA > |
Learn more about CERT > |
Choosing the right C coding standard can be difficult — but it doesn’t need to be.
Get help choosing a C coding standard:
📕 Related White Paper: HOW TO CHOOSE AN EMBEDDED C Coding STANDARD
Important C++ Coding Standards
The C++ programming language is larger and more complex than C. Like C, C++ is flexible. And it’s recognized for high performance.
But to have a maintainable codebase, it’s important to use a C++ coding rules. This will help you ensure that undefined and unpredictable behavior stays out of your code.
There are several established standards for C++. Some are specific to embedded industries concerned about functional safety — including MISRA, AUTOSAR, and JSF AV C++. Others are designed for secure coding, such as CERT.
Popular Embedded C++ Coding Standards
Learn more about MISRA > |
Learn more about AUTOSAR > |
Learn more about High Integrity C++ > |
Learn more about JSF AV C++ > |
Learn more about CERT > |
How to Enforce C Coding Standards and C++ Coding Standards With Static Code Analysis
You can have a coding standard — but that doesn’t mean it’s being followed.
Static analyzers — such as Helix QAC or Klocwork — are the best way to ensure that they are enforced. By using automated static analysis, you can ensure your code conforms before you spend time on peer code reviews. Plus, this makes code reviews and testing phases more effective.