fix: make library backward compatible with c99
Replaces use of static_assert with a macro that falls back to a typedef
trick for pre-C11 compilers. Ensures transfer_list_entry size check
works with older firmware toolchains.
Also, remove C11 setting; ensure the library honors whatever standard
version is passed by the user.
Change-Id: Ibe0d9524913739c58c418e46ab6498dacfdf0027
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b69df14..35c8379 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,6 @@
#
# Set global flags.
#
-set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_C_EXTENSIONS TRUE)
diff --git a/include/transfer_list.h b/include/transfer_list.h
index 333a6b2..1e4bd7b 100644
--- a/include/transfer_list.h
+++ b/include/transfer_list.h
@@ -109,8 +109,20 @@
*/
};
-static_assert(sizeof(struct transfer_list_entry) == 0x8U,
- "assert_transfer_list_entry_size");
+/*
+ * Provide a backward-compatible implementation of static_assert.
+ * This keyword was introduced in C11, so it may be unavailable in
+ * projects targeting older C standards.
+ */
+#if __STDC_VERSION__ >= 201112L
+#define LIBTL_STATIC_ASSERT(cond, msg) _Static_assert(cond, #msg)
+#else
+#define LIBTL_STATIC_ASSERT(cond, msg) \
+ typedef char static_assertion_##msg[(cond) ? 1 : -1]
+#endif
+
+LIBTL_STATIC_ASSERT(sizeof(struct transfer_list_entry) == 0x8U,
+ assert_transfer_list_entry_size);
void transfer_list_dump(struct transfer_list_header *tl);
void transfer_entry_dump(struct transfer_list_entry *te);