C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [[packed]] std::unaligned

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 9 Dec 2023 22:14:01 +0000
On Saturday, December 9, 2023, Frederick Virchanza Gotham wrote:
>
>
> In both of these use cases, I'd much prefer if we could do the following:
>
> struct TokenInfo {
> long unsigned a;
> char b;
> long unsigned c;
> char d;
> };
>
> typedef struct TokenInfo [[packed]] TicketInfo;
>
> So now 'TicketInfo' is a packed form of the 'TokenInfo' struct.
>


Actually let me go a bit further with this. When you have:

    struct TokenInfo {
        long unsigned a;
        char b;
        long unsigned c;
        char d;
    };

    typedef struct TokenInfo [[packed]] TicketInfo;

The compiler treats it as if you had written:

    struct TokenInfo {
        long unsigned a;
        char b;
        long unsigned c;
        char d;
    };

   struct TicketInfo {
        unaligned<long unsigned> a;
        unaligned<char> b;
        unaligned<long unsigned> c;
        unaligned<char> d;
    };

Received on 2023-12-09 22:14:03