aboutsummaryrefslogtreecommitdiff
path: root/fsm/tk.h
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-07 08:09:10 -0700
committerSelene ToyKeeper2023-11-07 08:09:10 -0700
commite00326a6db6671414b43ee15e092c57ea976102f (patch)
tree314608a1c7ba0d0177cab6ead8186638aa8a7e64 /fsm/tk.h
parentmemes (diff)
downloadanduril-e00326a6db6671414b43ee15e092c57ea976102f.tar.gz
anduril-e00326a6db6671414b43ee15e092c57ea976102f.tar.bz2
anduril-e00326a6db6671414b43ee15e092c57ea976102f.zip
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
Diffstat (limited to 'fsm/tk.h')
-rw-r--r--fsm/tk.h14
1 files changed, 14 insertions, 0 deletions
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)])); }
+