C++ Logo

std-discussion

Advanced search

Re: Padding bits stability

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Sun, 10 Nov 2024 21:57:06 +0100
On 10/11/2024 21.45, Mykola Garkusha via Std-Discussion wrote:
> Hi all,
>
> Currently(unlike C), the standard does not guarantee that padding bits may retain specific values even between sequential reads. Let's exclude tail padding re-use for potentially-overlapping sub-objects. as it is a slightly different matter related to OOP in C++ .
>
> In C, padding bits are guaranteed to say the same unless you modify the value!

Yes.

> Also looks like Clang and GCC also follow it, particularly to facilitate atomic operations on objects with padding bits.
> Clang and GCC even go further by providing intrinsics to clear padding bits (for example *__builtin_clear_padding* in GCC).
>
> Is there any chance C++ standard would allow this officially to come closer to the behaviour in C?

How would you want to inspect those padding bits portably? And why?
What's the use-case?

Jens

Received on 2024-11-10 20:57:09