C++ Logo


Advanced search

Subject: [std-proposals] Allowing access to object representations
From: Tjernstrom, Staffan (Staffan.Tjernstrom_at_[hidden])
Date: 2019-08-22 08:08:23

>I believe we should clarify the wording such that it becomes unambiguous that ch points to a *byte* of x. We should also clarify that this is not UB, even if 100000 does not fit into a char, as this ?fitting the whole object into a char" is >not at all what should be going on. We should also fix the wording to allow to access the other bytes of x, not just the first one, without causing UB (by allowing pointer arithmetic and looking at the other addresses inside the char >array that provides storage for x).
>This would give us a portable way of looking at the bytes of an object (which ought to be possible anyway ? this is why we have the ?char and std::byte? can alias any type? rule in the first place).
>I think if we would have such a fix, then together with Richard?s P0593 this would be a comprehensive plug for this gaping hole in the language.
>What do y?all think?


Whilst we're at it, P0593 would be greater if it applied the bless for the duration of the storage, that is to say

. get buffer
. bless buffer
. read bytes into buffer
. reinterpret buffer as type_1
. switch on deferenced pointer value
. reinterpret buffer as type_2, type_3, ...., type_n

would be defined / well-formed behaviour.

But I regretfully accept the reality of that kind of "bless allows aliasing" never gaining consensus.


IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups