46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
#error "GCC is currently not supported due to volatile union packed struct issue. Use clang instead"
|
|
#endif
|
|
|
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 4)) || defined(__clang__) || defined(__TINYC__)
|
|
|
|
#if defined(__TINYC__)
|
|
|
|
#define PACKED(x, s) \
|
|
_Pragma("pack(1)") \
|
|
union { \
|
|
s value; \
|
|
x __attribute__((packed)) fields; \
|
|
} \
|
|
_Pragma("pack(1)")
|
|
|
|
#define PACKEDM(x, s, n) \
|
|
_Pragma("pack(1)") \
|
|
union { \
|
|
s value[n]; \
|
|
x __attribute__((packed)) fields; \
|
|
} \
|
|
_Pragma("pack(1)")
|
|
|
|
#else
|
|
|
|
#define PACKED(x, s) \
|
|
union { \
|
|
s value; \
|
|
x __attribute__((packed, aligned(sizeof(s)))) fields; \
|
|
} __attribute__((packed, aligned(sizeof(s))))
|
|
|
|
#define PACKEDM(x, s, n) \
|
|
union { \
|
|
s value[n]; \
|
|
x __attribute__((packed, aligned(sizeof(s)))) fields; \
|
|
} __attribute__((packed, aligned(sizeof(s))))
|
|
|
|
#endif
|
|
|
|
#else
|
|
#error "Packed bit-fields of type char were not properly bit-packed on many targets prior to GCC 4.4, upgrade to GCC >= 4.4."
|
|
#endif |