Coding standards are collections of coding rules, guidelines, and best practices. Using the right one will help you write cleaner code.

Here we explain why coding standards are important, so consider this your guide to finding and using coding rules and guidelines.

Read along or jump to the section that interests you most:

 


 

What Are 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.


Why Coding Standards Are Important

The reason why coding standards are important is because 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 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++.

9 Best Practices for Using Coding Standards

1. Know why you're using it.

2. Choose the best one for your industry.

get more best practices

Image Blog QAC Using Coding Standards

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 a C coding standard 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 one 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 >

Should I Adopt C++17?

And how will it impact compliance?

FIND OUT

Image Blog QAC Adopt CPP 17

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.

How to Enforce Coding Standards With Automated Static Analysis

LEARN HOW

Images Blog QAC Coding Standards Automated Static Analysis

Use Perforce Static Analyzers to Ensure Compliance With Coding Standards

Perforce static analyzersHelix QAC and Klocwork — have been trusted for over 30 years to deliver the most accurate and precise results to mission-critical project teams across a variety of industries. You can even configure them to support custom coding rules that are specific to your development team.

See how Perforce static analyzers will help you comply with C coding standards C++ coding standards, and other coding standards.