-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
State: don't staleState: Tell state-bot to ignore this issueState: Tell state-bot to ignore this issueType: bugThe issue reports a bug / The PR fixes a bug (including spelling errors)The issue reports a bug / The PR fixes a bug (including spelling errors)Type: cleanupThe issue proposes a clean-up / The PR cleans-up parts of the codebase / documentationThe issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Description
Description
The types in byteorder.h like be_uint64_t look like this:
/**
* @brief A 64 bit integer in big endian aka network byte order.
* @details This is a wrapper around an uint64_t to catch missing conversions
* between different byte orders at compile time.
*/
typedef union __attribute__((packed)) {
uint64_t u64; /**< 64 bit representation */
uint8_t u8[8]; /**< 8 bit representation */
uint16_t u16[4]; /**< 16 bit representation */
uint32_t u32[2]; /**< 32 bit representation */
be_uint16_t b16[4]; /**< big endian 16 bit representation */
be_uint32_t b32[2]; /**< big endian 32 bit representation */
} be_uint64_t; - Why does the type contain
__attribute__((packed))? This will for the compiler to assume all accesses are unaligned. This reduces performance and increases ROM size when accessing it.- When used in a some
foo_hdr_tstructure, that structure should have the__attribute__((packed))attribute instead. This would prevent unaligned accesses to incorrectly be assumed to be aligned when casting auint8_t *-buffer to a header struct. But at the same time,be_uint64_tused outside of headers won't be effected by the performance penalty for no reason.
- When used in a some
- Why does it contain both
uint16_t u16[4]andbe_uint16_t b16[4]?- Especially with the poor member documentation, this could easily mislead people to assume the
u16member contains host byte order and theb16member contains network byte order.
- Especially with the poor member documentation, this could easily mislead people to assume the
Versions
Up to current master
Metadata
Metadata
Assignees
Labels
State: don't staleState: Tell state-bot to ignore this issueState: Tell state-bot to ignore this issueType: bugThe issue reports a bug / The PR fixes a bug (including spelling errors)The issue reports a bug / The PR fixes a bug (including spelling errors)Type: cleanupThe issue proposes a clean-up / The PR cleans-up parts of the codebase / documentationThe issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation