Assuming we have 2 files DIO.c and DIO.h. I used to #include all necessary header files in DIO.h and only #include DIO.h in DIO.c. while working on drivers for ATmega32, I found out that some functions are declared implicitly while including other modules. This made me wonder is that right to include all files in header file instead of source file? and how what
i'm doing currently affects dependency?
After visiting some repos on github i found out that they never #include anything in header files, and only include everything in C file, which made me more confused about what about typedefs? how they use them without including the header file containing them?
Here is an example of DIO.h file:
#include "Dio_Private.h"
#include "Dio_Config.h"
#include "../../Utilities/Macros.h"
and here is an example of DIO.c file:
#include "DIO.h"
If the answer was that I should include all header files in C file, what about enums?
for example, if I want to use enums defined in DIO.h file in any other module, should I now seperate these enums in another header file and only #include it?
Thanks in advance :)
Dio.his exporting an interface of certain Dio-functions, what areDio_Private.handutilities/Macros.h.. what are you writing then Dio.c for? Worst thing is, that such definitions then through header include hierarchies are visible in higher layers and even clash there with other names.Dio_LevelType Dio_ReadChannel(Dio_ChannelType chn);andvoid Dio_WriteChannel(Dio_ChannelType chn, Dio_LevelType lvl);in the header, plus a Dio_Cgh.h include defining the channel IDs. The rest is handled in the Dio.c file. No Set/ClrBit macros, no HW registers outside Dio.