Skip to content

Commit

Permalink
Fix size of unaligned_type on Windows
Browse files Browse the repository at this point in the history
Multiple inheritance leads to additional 1 byte for the second base class.
Fixing it by not inheriting but aggregating via typedef.
  • Loading branch information
rolandreichweinbmw committed Mar 2, 2025
1 parent 9bf2733 commit 12c07f7
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions include/etl/unaligned_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,15 @@ namespace etl
//*************************************************************************
template <typename T, int Endian_>
ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage<sizeof(T)>
, public private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true>
{
public:

ETL_STATIC_ASSERT(etl::is_integral<T>::value || etl::is_floating_point<T>::value, "Unaligned type must be integral or floating point");

typedef T value_type;

typedef private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;

typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::storage_type storage_type;
typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::pointer pointer;
typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_pointer const_pointer;
Expand All @@ -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);
}

//*************************************************************************
Expand All @@ -506,7 +507,7 @@ namespace etl
//*************************************************************************
unaligned_type(const unaligned_type<T, Endian>& other)
{
this->copy_store_to_store(other.data(), Endian, this->storage);
unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);
}

//*************************************************************************
Expand All @@ -515,15 +516,15 @@ namespace etl
template <int Endian_Other>
unaligned_type(const unaligned_type<T, Endian_Other>& other)
{
this->copy_store_to_store(other.data(), Endian_Other, this->storage);
unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
}

//*************************************************************************
/// Assignment operator
//*************************************************************************
unaligned_type& operator =(T value)
{
this->copy_value_to_store(value, this->storage);
unaligned_copy::copy_value_to_store(value, this->storage);

return *this;
}
Expand All @@ -533,7 +534,7 @@ namespace etl
//*************************************************************************
unaligned_type& operator =(const unaligned_type<T, Endian_>& other)
{
this->copy_store_to_store(other.data(), Endian_, this->storage);
unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage);

return *this;
}
Expand All @@ -544,7 +545,7 @@ namespace etl
template <int Endian_Other>
unaligned_type& operator =(const unaligned_type<T, Endian_Other>& 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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -589,7 +590,6 @@ namespace etl
//*************************************************************************
template <typename T, int Endian_>
ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>
, public private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true>
{
public:

Expand All @@ -600,6 +600,8 @@ namespace etl

typedef T value_type;

typedef private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;

typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::storage_type storage_type;
typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::pointer pointer;
typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_pointer const_pointer;
Expand All @@ -625,7 +627,7 @@ namespace etl
unaligned_type_ext(T value, pointer storage_)
: private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
{
this->copy_value_to_store(value, this->storage);
unaligned_copy::copy_value_to_store(value, this->storage);
}

//*************************************************************************
Expand All @@ -635,7 +637,7 @@ namespace etl
unaligned_type_ext(const unaligned_type_ext<T, Endian_Other>& other, pointer storage_)
: private_unaligned_type::unaligned_type_storage_ext<Size>(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
Expand Down Expand Up @@ -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;
}
Expand All @@ -680,7 +682,7 @@ namespace etl
//*************************************************************************
unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian>& other)
{
this->copy_store_to_store(other.data(), Endian, this->storage);
unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);

return *this;
}
Expand All @@ -691,7 +693,7 @@ namespace etl
template <int Endian_Other>
unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian_Other>& 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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 12c07f7

Please sign in to comment.