From e00326a6db6671414b43ee15e092c57ea976102f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 7 Nov 2023 08:09:10 -0700 Subject: made build fail if eeprom data bigger than MCU's eeprom size Based on techniques suggested by DurvalMenezes here: https://github.com/ToyKeeper/anduril/pull/4 --- fsm/tk.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'fsm/tk.h') diff --git a/fsm/tk.h b/fsm/tk.h index 785808d..f2e7efe 100644 --- a/fsm/tk.h +++ b/fsm/tk.h @@ -24,3 +24,17 @@ // use it like this: //#include incfile(CONFIGFILE) + +// cause a build failure if `condition` is true +// (gcc compile trick taken from an old version of include/linux/kernel.h) +// more info here: +// https://scaryreasoner.wordpress.com/2009/02/28/checking-sizeof-at-compile-time/ +#define BUILD_FAIL_IF(name, condition) \ + __attribute__((unused)) static void name() \ + { ((void)sizeof(char[1 - 2*!!(condition)])); } + +// cause a build failure if `condition` is false +#define BUILD_ASSERT(name, condition) \ + __attribute__((unused)) static void name() \ + { ((void)sizeof(char[1 - 2*!(condition)])); } + -- cgit v1.2.3