digitalmars.D.bugs - [Issue 10512] New: Reinterpret-casting struct fields as another struct should be safe
- d-bugmail puremagic.com (41/41) Jun 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10512
- d-bugmail puremagic.com (13/13) Jun 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10512
http://d.puremagic.com/issues/show_bug.cgi?id=10512 Summary: Reinterpret-casting struct fields as another struct should be safe Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: tommitissari hotmail.com The order and alignment of struct fields are statically known. Therefore the compiler should be able to verify that the following code is memory safe and let it compile: safe: struct A { int i; short s; byte b; } struct B { long l; int i; short s; byte b; } void main() { A a; B b; *(cast(A*) &b.i) = a; // [1] } [1] Error: cast from int* to A* not allowed in safe code -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 30 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10512 Maxim Fomin <maxim maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim maxim-fomin.ru --- These structs may come from different implementations with different alignments. In general case structs may include other aggregate types where situation may be complicated. D has unions for such tricks (you are better with placing long l in last place). In my opinion this is wontfix. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 30 2013