Is using #include "component.c" considered bad practice
Generally speaking, yes.
Usually, the preprocessor's file-inclusion feature is reserved to support factoring common declarations into their own files, so that they don't need to be duplicated in multiple sources. Such factoring provides huge benefits for maintainability in all but the smallest projects, and it is a near-requirement for libraries to be usable. A file containing only such declarations is conventionally called a "header", and is conventionally named with a .h
suffix. In this sense, then, the issue is partially about file naming and programming patterns.
On the other hand, C source files containing function or object definitions (as opposed to declarations) are conventionally named with a .c
suffix. The C language forbids multiple external definitions of the same identifier (function or variable name) in the same program, so such .c
files cannot be #include
d into more than one translation unit contributing to a program, and if they are included into even one, then they must not also be compiled directly. The usual way to build a program from multiple .c
files is to compile them independently and then link them together.
Provided one is sure to avoid duplicate definitions, it is not inherently wrong to #include
one .c
file into another. But this makes sense only as a special-purpose arrangement. It creates extra risk, and it provides no particular advantage as far as the language specification goes. Also, because it runs contrary to convention, it tends to surprise and confuse developers -- maybe even more experienced future you.
is there any misra standard rule violation? (potentially rule 3-3-1)
It does not inherently violate MISRA rule 3-3-1, but it makes it less painful to write code that does violate that rule. That is by making it feasible to have all the needed external declarations in a single .c file plus its inclusions, instead of providing a separate header.
I don't see any other MISRA-2012 rule that such an inclusion would violate. But that would not hold much water with me in code review.