C++ Logo

std-proposals

Advanced search

Re: Allowing access to object representations

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Wed, 21 Aug 2019 22:50:06 +0300
On 21/08/2019 22:46, sdkrystian via Std-Proposals wrote:
> For an object of class type, what would the range of representable values be? For example:
>
> struct S { int a, b, c, d; };
>
> void f()
> {
> S a{};
> char b = *reinterpret_cast<char*>(&a); // cast leaves value unchanged, range of representable values for an object of type S is logically greater than char, but what wording specifies that?
> }

I don't think it is specified.
I think that even `struct S { char c; };` and `char` represent completely different sets of values.

> Sent from my Samsung Galaxy smartphone.
>
> -------- Original message --------
> From: "language.lawyer--- via Std-Proposals" <std-proposals_at_[hidden]>
> Date: 8/21/19 15:32 (GMT-05:00)
> To: std-proposals_at_[hidden]
> Cc: language.lawyer_at_[hidden]
> Subject: Re: [std-proposals] Allowing access to object representations
>
> On 21/08/2019 22:31, sdkrystian via Std-Proposals wrote:
> > The example I provided is not the best, since 42 is small enough for unsigned char and int to work as expected, imagine that I wrote a bigger number, such as 1000
>
> This is covered by http://eel.is/c++draft/expr.pre#4
>
> > Sent from my Samsung Galaxy smartphone.
> >
> > -------- Original message --------
> > From: Timur Doumler via Std-Proposals <std-proposals_at_[hidden]>
> > Date: 8/21/19 15:11 (GMT-05:00)
> > To: std-proposals_at_[hidden]
> > Cc: Timur Doumler <cpp_at_[hidden]>
> > Subject: Re: [std-proposals] Allowing access to object representations
> >
> > This doesn't make sense to me. If I have an object of type int (or, say, a struct containing an int), then the value has 4 bytes. If I access that value by dereferencing a char pointer that aliases that object, all I can ever get from that char is a single byte. How can this be "the object"?
> >
> > Cheers,
> > Timur
> >
> > > On 21 Aug 2019, at 20:59, language.lawyer--- via Std-Proposals <std-proposals_at_[hidden]> wrote:
> > >
> > >> On 21/08/2019 21:55, Krystian Stasiowski via Std-Proposals wrote:
> > >> Yes, you access the value of the object of the object, however, since its not specified what exactly you get
> > >
> > > It is specified: you get the value contained in the object.
> > >
> > >> http://eel.is/c++draft/conv.lval#3.4
> > >
> > > Indeed, it is specified here.
> > > --
> > > Std-Proposals mailing list
> > > Std-Proposals_at_[hidden]
> > > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> >
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> >
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2019-08-21 14:52:11