C++ Logo


Advanced search

Subject: Re: [std-proposals] Allowing access to object representations
From: language.lawyer_at_[hidden]
Date: 2019-08-21 15:36:56

On 21/08/2019 22:51, language.lawyer_at_[hidden] wrote:
> On 21/08/2019 22:44, Timur Doumler via Std-Proposals wrote:
>> So you're saying that, even without any pointer arithmetic, just this code:
>> int x = 100000;
>> std::cout << *reinterpret_cast<char*>(&x);
>> has undefined behaviour?
>> If that's the case then this is even more insane than I thought. Please clarify whether this is really what you're saying here!
> I suspect you was trying to answer my mail, but anyways yes, I think that your example has UB.

UB if 100000 is outside of the range representable by char, ofc.
On a platform where char represents the same range of values as int the code obviously won't have UB.

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups