News for hackers. Stuff that matters.
Re:A case against text protocols by pwdisswordfish8 on Thursday June 17, 2021 @11:03AM (#27540330)
Better yet is using wrappers for char arrays paired with helper functions:

    typedef struct { unsigned char data[2]; } u16be_t;

    inline static uint16_t get_u16be(const u16be_t *p) {
        uint16_t result = 0;
        result |= (uint16_t) p->data[0] << 8;
        result |= (uint16_t) p->data[1];
        return result;
    }

    inline static void put_u16be(u16be_t *p, uint16_t value) {
        p->data[0] = value >> 8;
        p->data[1] = value;
    }
Perfectly portable (as long as CHAR_BIT = 8), type-safe, and on modern compilers it generates no overhead over direct memory accesses.

There are no comments on this comment yet.