Here is an improved version (the first version is below). This one does not depend on the cast being uint8_t
; it will work with any FLASH_BLOCK_SIZE
replacement list of the form ((some type) number)
.
#define MYPROG_BLOCK_SIZE 64
#define FLASH_BLOCK_SIZE ((uint8_t)64)
#define B(x)
#define C(x) B x
#define D(x) C x
#if MYPROG_BLOCK_SIZE != D(FLASH_BLOCK_SIZE)
#error "mismatch between actual block size and defined block size"
#endif
Here is the original version:
#define MYPROG_BLOCK_SIZE 64
#define FLASH_BLOCK_SIZE ((uint8_t)64)
#define uint8_t
#define Helper(x) x
#define Deparenthesize(x) Helper x
#if MYPROG_BLOCK_SIZE != Deparenthesize(Deparenthesize(FLASH_BLOCK_SIZE))
#error "mismatch between actual block size and defined block size"
#endif
#undef uint8_t
When writing code, I would prefer a static assert, but the above does what you requested in the preprocessor.