A coding standard is a collection of coding rules, guidelines, and best practices. Using the right one helps you write cleaner code.

Consider this your guide to finding and using coding standards.

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

Coding standards are important for safety, security, and reliability.

Every development team should use a coding standard. 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 main drivers for using a coding standard:

  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, 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”


[RELATED WHITE PAPER: WHY FUNCTIONAL SAFETY IS CRITICAL FOR EMBEDDED SOFTWARE]
 

Every coding standard 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 coding standard for your industry.

get more best practices

Coding standards best practices may vary by which standard you use, e.g. MISRA or AUTOSAR.

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 coding 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 >


Choosing the right C++ coding standard can be difficult — but it doesn’t need to be.

Get help choosing:


[RELATED WHITE PAPER: HOW TO CHOOSE AN EMBEDDED C++ CODING STANDARD]

Should I Adopt C++17?

And how will it impact compliance?

FIND OUT

Find out what's in C++17.

How to Enforce Coding Rules 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 — are the best way to enforce coding standards. 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

Enforcing Coding Standards with Automated Static Analysis

Try Helix QAC for Coding Standard Compliance

Helix QAC is one of the most accurate static analyzers for enforcing C/C++ coding standards. You can even configure it to support custom coding rules that are specific to your development team.

See how Helix QAC will help you comply with your coding standard.