C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Subscript aliasing

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 8 Mar 2024 00:33:00 +0000
On Thu, Mar 7, 2024 at 10:55 PM veronica alphonso wrote:
>
> union
> {
> float my_vec[3];
> struct
> {
> float x, y, z;
> };
> };


The following struct behaves the way you want it to:

    struct MyStruct1 {
        float vars[3u];
        float &a = vars[0u], &b = vars[1u], &c = vars[2u];
    };

However there are 3 problems with it:
(1) The size is 32 bytes instead of 3 bytes
(2) The alignment is 8 bytes instead of 1 byte
(3) It is no longer trivially constructible

I'm just pointing these things out, because if you write a paper there
should be a section about possible alternatives.

Received on 2024-03-08 00:33:13