I am writing a MISRA compliant code that runs on a microcontroller, and this program must be written in the C language.
I would like to design my software according to the object-oriented design. However, the C-language lacks OOP support.
Therefore, I decided to create "classes" and "packages" through C-files and Folders, respectively.
Currently, all legacy function names were having the following names: <Module_Name>_f_<Function_Name>_<Return type>.
This function naming convention works as long as there is only a single Module. However, if I add SubModules or even SubSubModules, then the function name might get confusing. For example, having Module, Submodule, and a SubSubModule might end up in one the following function names:
<Module_Name><SubModule_Name><SubSubModule_Name>_f_<Function_Name>_<Return type><Module_Name>_<SubModule_Name>_<SubSubModule_Name>_f_<Function_Name>_<Return type><Module_Name>_f_<SubModule_Name>_<SubSubModule_Name>_<Function_Name>_<Return type>...
What would be a good name for such functions, and their respective C-files? I would like to have a naming convention that one can read and still understand the "class"/"package" structure?
To make it more clear, we can take more concrete example with the following file structure containing Folders and C-files:
Module (Folder)
- SubModule_1 (Folder)
- SubSubModule_1_1.c
- SubSubModule_1_2.c
- SubSubSubModule_1_2_1.c (Maybe also put in a seperate Sub-Folder?)
- SubSubSubModule_1_2_2.c (Maybe also put in a seperate Sub-Folder?)
...
- SubModule_n (Folder)
- SubSubModule_n_1.c
- SubSubModule_n_2.c
...
The above file structure might look like this in an OOP pseudocode:
class Module:
begin Module;
# Field Declarations
SubModule_1 subModule_1_Instance;
SubModule_2 subModule_2_Instance;
...
# Function declarations
Module_f_<Function_Name>_<return type>;
...
end Module;
class SubModule_1:
begin SubModule_1;
# Field Declarations
SubSubModule_1_1 subSubModule_1_1_Instance;
SubSubModule_1_2 subSubModule_1_2_Instance;
...
# Function declarations
ModuleSubModule1_f_<Function_Name>_<return type>;
OR
Module_SubModule1_f_<Function_Name>_<return type>;
OR
Module_f_SubModule1_f_<Function_Name>_<return type>;
...
end SubModule_1;
class SubSubModule_1_1:
begin SubSubModule_1_1;
# Function declarations
ModuleSubModule1SubModuleSubModule11_f_<Function_Name>_<return type>;
OR
Module_SubModule1_SubModule11_f_<Function_Name>_<return type>;
OR
Module_f_SubModule1_SubModule11__f_<Function_Name>_<return type>;
...
end SubSubModule_1_1;
So for the SubSubModule_1_1, I might end up with:
ModuleSubModule1SubModuleSubModule11_f_<Function_Name>_<return type>;Module_SubModule1_SubModule11_f_<Function_Name>_<return type>;Module_f_SubModule1_SubModule11__f_<Function_Name>_<return type>;
Is there maybe a better way to name those functions? I am looking forward to Your replays/alternatives. Thank you in advance.