I want to write a .h file conforming to C89 that would be understood by most C preprocessors like gcc, cl (Visual Studio) etc. and that would determine the data model used, i.e. how many bits the (unsigned) short
, (unsigned) int
and (unsigned) long
types occupy. Where can I find the necessary macros? For instance, are there macros I can evaluate in order to find out whether the data model is e.g. ILP32, LP64, LLP64 or something else? It is fine for me to use compiler-specific macros, but I do not want to use architecture-specific or OS-specific macros. If possible, please also provide the necessary macros to check which compiler is used. Thank you!
ADDED 2: The goal is to allow for type definitions depending on the data model. For instance, if long
is at least 48-bit wide, a 48-bit key type could be defined as long
, but if not, I would need a struct
for that. On the other hand, I do not want to rely on anything not guaranteed by C89, like "long
is either 32-bit or 64-bit, so if ULONG_MAX != 0xFFFFFFFFlu
, then long is wider than 48-bit", which does not have to be true on all C89-conforming compilers.
ADDED 1:Here, the predefined GCC macros are described. Hence I can do the following:
#if defined(__GNUC__)#define SHRT_BIT __SHRT_WIDTH__#define INT_BIT __INT_WIDTH__#define LONG_BIT __LONG_WIDTH__#elif ???# ???#endifprintf("short is %u-bit\n""int is %u-bit\n""long is %u-bit\n", SHRT_BIT, INT_BIT, LONG_BIT);
Are there similar macros for other widely used compilers like cl (Visual Studio), which I could add at the location of the ???
in the code?