cstandardsmisrasafety-critical

Include .c instead of header(.h) - MISRA C


Is using #include "component.c" considered bad practice or is there any misra standard rule violation? (potentially rule 3-3-1)

So far, I understand that it is a commonly categorized as bad practice but can be used in certain scenarios, would it be any particular concern for safety-critical applications?

Misra rule 3-3-1 states that Objects or functions with external linkage shall be declared in a header file


Solution

  • When you write a program like that, it is called a unity build. A good example of such a program is the compiler for the Odin programming language. So it can be done, but like anything else, there are tradeoffs.

    pros

    cons

    Does this violate MIRSA?

    I don't actually know, but it doesn't violate the rule you posted:

    Misra rule 3-3-1 states that Objects or functions with external linkage shall be declared in a header file

    By including a C file, you know longer have external linkage because they are in the same translation unit.