From 12c07f794d38f009eeaddab08f8b11a8a49ea268 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 2 Mar 2025 22:34:37 +0100 Subject: [PATCH] Fix size of unaligned_type on Windows Multiple inheritance leads to additional 1 byte for the second base class. Fixing it by not inheriting but aggregating via typedef. --- include/etl/unaligned_type.h | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 8910f864d..87519dbff 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -449,7 +449,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -457,6 +456,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage::const_pointer const_pointer; @@ -480,7 +481,7 @@ namespace etl //************************************************************************* unaligned_type(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -506,7 +507,7 @@ namespace etl //************************************************************************* unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); } //************************************************************************* @@ -515,7 +516,7 @@ namespace etl template unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } //************************************************************************* @@ -523,7 +524,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -533,7 +534,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage); return *this; } @@ -544,7 +545,7 @@ namespace etl template unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -556,7 +557,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -568,7 +569,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -589,7 +590,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -600,6 +600,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage_ext::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage_ext::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage_ext::const_pointer const_pointer; @@ -625,7 +627,7 @@ namespace etl unaligned_type_ext(T value, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -635,7 +637,7 @@ namespace etl unaligned_type_ext(const unaligned_type_ext& other, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } #if ETL_USING_CPP11 @@ -670,7 +672,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -680,7 +682,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); return *this; } @@ -691,7 +693,7 @@ namespace etl template unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -735,7 +737,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -747,7 +749,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; }