Re: Why is it difficult to reference arrays in structs?

2019-10-02 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:32:52 UTC, Brett wrote: Ok, fine! auto r = Now r is a reference, great! No, r is a pointer, not a reference. D does not have reference variables. But now the semantics of using the array completely change and errors abound! Probably because you're

Re: Why is it difficult to reference arrays in structs?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:32:52 UTC, Brett wrote: struct Y { double q; } struct X { Y[] a; } X x; auto r = x.a; r is not a reference?!?! Arrays are (ptr,length) pairs. r is a copy of them: #! /usr/bin/env rdmd import std.stdio; struct X { int[] a; } void main() {

Why is it difficult to reference arrays in structs?

2019-10-02 Thread Brett via Digitalmars-d-learn
struct Y { double q; } struct X { Y[] a; } X x; auto r = x.a; r is not a reference?!?! When updating x.a, r is not updated ;/ [I'm not sure if it just creates a slice or what] Ok, fine! auto r = Now r is a reference, great!. But now the semantics of using the array completely change