Issue
I am trying to unit test code on x86 that uses uint_least8_t. On one of the targets this is actually a uint16_t so I'd like to be able to unit test with uint_least8_t being both uint8_t and uint16_t. What's a good way of redefining uint_least8_t (and variants) to 16-bit types?
I tried to do a simple typedef uint16_t uint_least8_t;
but the compiler complains about the redefinition. I could replace all uint_least8_t with yet another type (ie. my_uint_least8_t
), but would prefer not to have to modify all the code. Is there an easy way to achieve this?
(C11, GCC)
Solution
Create your own stdint.h
file in some test dir. Add the path to that to compiler include path with -I
for the whole project.
In that stdint.h
do #include_next <stdint.h>
. After that in that stdint.h
#undef
all preprocessor macros when needed and #define uint_least8_t uint16_t
.
Answered By - KamilCuk Answer Checked By - David Marino (WPSolving Volunteer)