From 78cc8064c5a39605cbbf6b0157d97c57cbd18775 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 28 Dec 2017 09:15:50 +0100 Subject: [PATCH] api-version: A better error message Use `static_assert` instead of `#error` to report an API mismatch, resulting in a much more informative error message. Thanks to @cdisselkoen for the request, and @noseglasses for the `static_assert` idea! Signed-off-by: Gergely Nagy --- src/Kaleidoscope.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Kaleidoscope.h b/src/Kaleidoscope.h index 27038d00..a8e199f2 100644 --- a/src/Kaleidoscope.h +++ b/src/Kaleidoscope.h @@ -56,7 +56,11 @@ extern HARDWARE_IMPLEMENTATION KeyboardHardware; * instead of cryptic compile errors. */ #if defined(KALEIDOSCOPE_REQUIRED_API_VERSION) && (KALEIDOSCOPE_REQUIRED_API_VERSION != KALEIDOSCOPE_API_VERSION) -#error Kaleidoscope API version mismatch! The plugin or sketch requires a different API version than what is available. +#define xstr(a) str(a) +#define str(a) #a +static_assert(KALEIDOSCOPE_REQUIRED_API_VERSION == KALEIDOSCOPE_API_VERSION, + "Kaleidoscope API version mismatch! We have version " xstr(KALEIDOSCOPE_API_VERSION) + " available, but version " xstr(KALEIDOSCOPE_REQUIRED_API_VERSION) " is required."); #endif const uint8_t KEYMAP_SIZE