Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It is not recommended to use .c files as header files in MISRA C, as it can violate the MISRA C rules related to the separation of interface and implementation.

Header files in MISRA C should contain only declarations, type definitions, and macro definitions, while the implementation code should be placed in source files (.c files). This separation is important for ensuring the modularity and portability of the code.

If you have code in a .c file that you want to use as a header file, you should move the declarations and definitions into a separate header file (.h) and include it in your source file.

For example, if you have the following function in a.c:

int foo(int x, int y)
{
   return x + y;
}

You should move the function declaration into a header file, a.h:

#ifndef A_H
#define A_H

int foo(int x, int y);

#endif /* A_H */

And then include a.h in your source file:

#include "a.h"

int main()
{
   int result = foo(3, 4);
   return 0;
}