A common use of typedefs is to enable the 'type' of a variable to convey a better idea of a variable's purpose without redefining the storage structure behind it.
However, I'm also seeing typedefs as a way to change the storage structure for a class of variables in one go.
For example, if I define
typedef uint32_t my_offset_t
and have variables of the type my_offset_t
, switching the code-base from uint32_t
to char
or uint64_t
is as simple as changing one line and recompiling (assuming I've used sizeof
rather than hard-coded sizes), except in the case of printf / scanf.
Is there a way to swap format-specifiers according to the type in some easy way, without wrapper functions around printf
/scanf
, if-elses, or ifdefs?
Thanks!
For anyone interested, I'm modifying an LKM that used 16-bit offsets to work with 32-bit offsets, but want it to be able to go to 64-bit (or something else!) offsets if necessary with minimal changes.