C++ Logo


Advanced search

Re: I need strict aliasing for simple types

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 20 Sep 2021 15:59:46 -0700
On Sunday, 19 September 2021 19:55:03 PDT Jason McKesson via Std-Discussion
> So it seems like you want to *prevent* strict aliasing for "simple
> types". And no, you can't just do that. You can use a `union` or a
> `variant`, but you can't arbitrarily shift between the two sets of
> types.
> You can reuse memory for a new type by just using placement-new over
> an array of storage.

You can also memcpy any memory to any other memory.

Size and endianness checks left as an exercise to the reader.

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

Received on 2021-09-20 17:59:53