The following technique is used by FreeBSD. The primitive data types that can appear in multiple headers are defined in the header <machine/_types.h>.
For example:
#ifndef _MACHINE__TYPES_H_
#define _MACHINE__TYPES_H_
typedef int __int32_t;
typedef unsigned int __uint32_t;
...
typedef __uint32_t __size_t;
...
#endif /* _MACHINE__TYPES_H_ */
In each of the headers that can define the size_t primitive system data type, we have the sequence
#ifndef _SIZE_T_DECLARED
typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
This way, the typedef for size_t is executed only once. |