Re: Is it safe in D to cast pointers to structures like this?

2020-01-14 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 14 January 2020 at 12:05:01 UTC, John Burton wrote: After years of C++ I have become paranoid about any casting of pointers being undefined behavior due to aliasing so want to see if :- FWIW, this is safe and portable in C++20: https://en.cppreference.com/w/cpp/numeric/bit_cast

Is it safe in D to cast pointers to structures like this?

2020-01-14 Thread John Burton via Digitalmars-d-learn
After years of C++ I have become paranoid about any casting of pointers being undefined behavior due to aliasing so want to see if :- 1) This is safe to do in D. 2) If not is there anything I can do to make it safe. 3) If not, what is the best approach? I have a void* pointing to a block of

pointers and structures

2011-04-17 Thread %u
what is the equivalent for this code in D? #include stdio.h main() { struct S { int i; }; struct S s, *s_ptr; s_ptr = s; s_ptr-i = 9; printf(%d\n, s_ptr-i); }

Re: pointers and structures

2011-04-17 Thread Christian Manning
On 17/04/2011 18:17, %u wrote: what is the equivalent for this code in D? #includestdio.h main() { struct S { int i; }; struct S s, *s_ptr; s_ptr =s; s_ptr-i = 9; printf(%d\n, s_ptr-i); }