When I create a header file that will be used by several developers, it is considered good programming practice to make this header file self-sufficient in terms of all the definitions and declarations used in it.
For example:
Header File 1: types.h
#ifndef TYPES_H #define TYPES_H typedef unsigned int uint16 #endif
Header File 2: myheader.h
#ifndef MYHEADER_H #define MYHEADER_H uint16 myfunc(void); #endif
I used uint16 in myheader.h without including types.h. Therefore, if someone wants to include myheader.h in the source file, he must first include "types.h" and then include "myheader.h". Thus, this actually forces the developer to include the header files in a specific order. I always thought of this as bad practice, but today I met some code in my company where, in order to get the function declared in one file, you need to include at least 4 other header files. So now I'm confused, I'm missing something, is there a place where this will be considered the expected behavior.
Pratt
source share