Skip to content

Commit 44d5c0b

Browse files
Packed unaligned_type
This way, unaligned_types like etl::be_uint32_t can be used in places where POD types are expected.
1 parent 99d7537 commit 44d5c0b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/etl/platform.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@ SOFTWARE.
454454
#define ETL_HAS_INITIALIZER_LIST 0
455455
#endif
456456

457+
//*************************************
458+
// Determine if the ETL should use __attribute__((packed).
459+
#if defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_INTEL)
460+
#define ETL_PACKED __attribute__((packed))
461+
#else
462+
#define ETL_PACKED
463+
#endif
464+
457465
//*************************************
458466
// Check for availability of certain builtins
459467
#include "profiles/determine_builtin_support.h"

include/etl/unaligned_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ namespace etl
227227
///\tparam Endian The endianness of the arithmetic type.
228228
//*************************************************************************
229229
template <typename T, int Endian_>
230-
class unaligned_type : public private_unaligned_type::unaligned_type_common<sizeof(T)>
230+
class ETL_PACKED unaligned_type : public private_unaligned_type::unaligned_type_common<sizeof(T)>
231231
{
232232
public:
233233

0 commit comments

Comments
 (0)