From 84eea5bb1ff2540639825d3b147dbd4655aa5152 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 14 Dec 2024 22:36:15 +0100 Subject: [PATCH] Packed unaligned_type (#989) This way, unaligned_types like etl::be_uint32_t can be used in places where POD types are expected. --- include/etl/platform.h | 8 ++++++++ include/etl/unaligned_type.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/etl/platform.h b/include/etl/platform.h index e66a0e08..f8d8752d 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -454,6 +454,14 @@ SOFTWARE. #define ETL_HAS_INITIALIZER_LIST 0 #endif +//************************************* +// Determine if the ETL should use __attribute__((packed). +#if defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_INTEL) + #define ETL_PACKED __attribute__((packed)) +#else + #define ETL_PACKED +#endif + //************************************* // Check for availability of certain builtins #include "profiles/determine_builtin_support.h" diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 9b4ae662..77e38ce1 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -227,7 +227,7 @@ namespace etl ///\tparam Endian The endianness of the arithmetic type. //************************************************************************* template - class unaligned_type : public private_unaligned_type::unaligned_type_common + class ETL_PACKED unaligned_type : public private_unaligned_type::unaligned_type_common { public: