Skip to content

Commit 12c07f7

Browse files
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.
1 parent 9bf2733 commit 12c07f7

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

include/etl/unaligned_type.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,15 @@ namespace etl
449449
//*************************************************************************
450450
template <typename T, int Endian_>
451451
ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage<sizeof(T)>
452-
, public private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true>
453452
{
454453
public:
455454

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

458457
typedef T value_type;
459458

459+
typedef private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;
460+
460461
typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::storage_type storage_type;
461462
typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::pointer pointer;
462463
typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_pointer const_pointer;
@@ -480,7 +481,7 @@ namespace etl
480481
//*************************************************************************
481482
unaligned_type(T value)
482483
{
483-
this->copy_value_to_store(value, this->storage);
484+
unaligned_copy::copy_value_to_store(value, this->storage);
484485
}
485486

486487
//*************************************************************************
@@ -506,7 +507,7 @@ namespace etl
506507
//*************************************************************************
507508
unaligned_type(const unaligned_type<T, Endian>& other)
508509
{
509-
this->copy_store_to_store(other.data(), Endian, this->storage);
510+
unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);
510511
}
511512

512513
//*************************************************************************
@@ -515,15 +516,15 @@ namespace etl
515516
template <int Endian_Other>
516517
unaligned_type(const unaligned_type<T, Endian_Other>& other)
517518
{
518-
this->copy_store_to_store(other.data(), Endian_Other, this->storage);
519+
unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
519520
}
520521

521522
//*************************************************************************
522523
/// Assignment operator
523524
//*************************************************************************
524525
unaligned_type& operator =(T value)
525526
{
526-
this->copy_value_to_store(value, this->storage);
527+
unaligned_copy::copy_value_to_store(value, this->storage);
527528

528529
return *this;
529530
}
@@ -533,7 +534,7 @@ namespace etl
533534
//*************************************************************************
534535
unaligned_type& operator =(const unaligned_type<T, Endian_>& other)
535536
{
536-
this->copy_store_to_store(other.data(), Endian_, this->storage);
537+
unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage);
537538

538539
return *this;
539540
}
@@ -544,7 +545,7 @@ namespace etl
544545
template <int Endian_Other>
545546
unaligned_type& operator =(const unaligned_type<T, Endian_Other>& other)
546547
{
547-
this->copy_store_to_store(other.data(), Endian_Other, this->storage);
548+
unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
548549

549550
return *this;
550551
}
@@ -556,7 +557,7 @@ namespace etl
556557
{
557558
T value = T();
558559

559-
this->copy_store_to_value(this->storage, value);
560+
unaligned_copy::copy_store_to_value(this->storage, value);
560561

561562
return value;
562563
}
@@ -568,7 +569,7 @@ namespace etl
568569
{
569570
T value = T();
570571

571-
this->copy_store_to_value(this->storage, value);
572+
unaligned_copy::copy_store_to_value(this->storage, value);
572573

573574
return value;
574575
}
@@ -589,7 +590,6 @@ namespace etl
589590
//*************************************************************************
590591
template <typename T, int Endian_>
591592
ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>
592-
, public private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true>
593593
{
594594
public:
595595

@@ -600,6 +600,8 @@ namespace etl
600600

601601
typedef T value_type;
602602

603+
typedef private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;
604+
603605
typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::storage_type storage_type;
604606
typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::pointer pointer;
605607
typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_pointer const_pointer;
@@ -625,7 +627,7 @@ namespace etl
625627
unaligned_type_ext(T value, pointer storage_)
626628
: private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
627629
{
628-
this->copy_value_to_store(value, this->storage);
630+
unaligned_copy::copy_value_to_store(value, this->storage);
629631
}
630632

631633
//*************************************************************************
@@ -635,7 +637,7 @@ namespace etl
635637
unaligned_type_ext(const unaligned_type_ext<T, Endian_Other>& other, pointer storage_)
636638
: private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
637639
{
638-
this->copy_store_to_store(other.data(), Endian_Other, this->storage);
640+
unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
639641
}
640642

641643
#if ETL_USING_CPP11
@@ -670,7 +672,7 @@ namespace etl
670672
//*************************************************************************
671673
unaligned_type_ext& operator =(T value)
672674
{
673-
this->copy_value_to_store(value, this->storage);
675+
unaligned_copy::copy_value_to_store(value, this->storage);
674676

675677
return *this;
676678
}
@@ -680,7 +682,7 @@ namespace etl
680682
//*************************************************************************
681683
unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian>& other)
682684
{
683-
this->copy_store_to_store(other.data(), Endian, this->storage);
685+
unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);
684686

685687
return *this;
686688
}
@@ -691,7 +693,7 @@ namespace etl
691693
template <int Endian_Other>
692694
unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian_Other>& other)
693695
{
694-
this->copy_store_to_store(other.data(), Endian_Other, this->storage);
696+
unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
695697

696698
return *this;
697699
}
@@ -735,7 +737,7 @@ namespace etl
735737
{
736738
T value = T();
737739

738-
this->copy_store_to_value(this->storage, value);
740+
unaligned_copy::copy_store_to_value(this->storage, value);
739741

740742
return value;
741743
}
@@ -747,7 +749,7 @@ namespace etl
747749
{
748750
T value = T();
749751

750-
this->copy_store_to_value(this->storage, value);
752+
unaligned_copy::copy_store_to_value(this->storage, value);
751753

752754
return value;
753755
}

0 commit comments

Comments
 (0)