Re: Casting between structs of the same size is treated as a bit cast?

2021-10-19 Thread jfondren via Digitalmars-d-learn
On Wednesday, 20 October 2021 at 04:14:37 UTC, Dave P. wrote: I am confused on how casting structs works. According to point 9 of https://dlang.org/spec/expression.html#CastExpression: Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: ```d S(v) `

Casting between structs of the same size is treated as a bit cast?

2021-10-19 Thread Dave P. via Digitalmars-d-learn
I am confused on how casting structs works. According to point 9 of https://dlang.org/spec/expression.html#CastExpression: Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: ```d S(v) ``` However, the following program compiles and the resulting

Re: casting between structs

2013-12-18 Thread bearophile
Mariusz `shd` Gliwiński: * it's currently safe One thing to remember when casting, is that when you cast const/immutable to mutable, then you can't mutate the data. Bye, bearophile

casting between structs

2013-12-18 Thread Mariusz `shd` Gliwiński
I'd like to reinterpret data as different type without copying. extern(C) struct A{ /* */ } struct B { A a; alias a this; } extern(C) A* f1(){ /* */ } B* f2() { return cast(B*) f1(); } Assuming that i cast() correct state, i'd like to know if: * it's currently safe * it's guaranteed to b