On Wed, Apr 22, 2020 at 1:14 PM Eric Botcazou <botca...@adacore.com> wrote: > > > I notice this statement in the documentation: > > Moreover, the use of type punning or aliasing to toggle the storage > > order is not supported; that is to say, a given scalar object cannot > > be accessed through distinct types that assign a different storage > > order to it. > > --- CUT --- > > But I am not 100% sure that is the case here but I hope I am wrong in > > saying this is not supported. > > This seems to me a fairly standard example of type punning: > > uint32_t u = 0x12345678; > uint32_t bu = ((upal_u32be_t*)&u)->val; > > u = 0x12345678; > uint32_t lu = ((upal_u32le_t*)&u)->val; > > u is accessed through upal_u32be_t and upal_u32le_t, i.e. BE and LE.
What if we had this: uint32_t u = 0x12345678; upal_u32be_t tempb; memcpy (&tempb, &u, sizeof(uint32_t)); uint32_t bu = tempb.val; Is that valid? We still run into the wrong code with the above case. memcpy here should be considered a byte-by-byte copy and therefor should not have any type punning except for to bytes. Thanks, Andrew Pinski > > -- > Eric Botcazou