C++ Logo


Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 06 Dec 2023 09:26:41 -0800
On Wednesday, 6 December 2023 09:01:06 PST Frederick Virchanza Gotham via Std-
Proposals wrote:
> So how would "std::unaligned<Trivial>" work?

Implementation detail. We don't need to discuss how to make it work with
standard C++, only that it should be possible for compilers to implement it.

GCC-like implementations will probably do:
  __attribute__((packed, aligned(1))) Trivial _M_data;

> Would it lack tail padding?

Yes, by definition. Alignment and tail padding are two sides of the same coin:
tail padding *exists* so a type's size is a multiple of its alignment.

> Or would it lack tail padding and also lack padding between
> members?

What members plural? There's only one.

> Then what will std::unaligned<Monkey> do? Will it take out just the
> tail padding, or will it take out the 3 pieces of padding?

No, your struct Monkey is unmodified. It is just allowed to remain unaligned
wherever it is placed in memory if used as std::unaligned<Monkey>.

If you want to remove the internal padding, use std::unaligned in the members
of your Monkey struct.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-12-06 17:26:43