Re: struct / cast / ? design problem

2015-03-16 Thread via Digitalmars-d-learn
The problem in your example is that your making a copy of the returned data. Of course any changes to that copy won't affect the original. You need to return a pointer to it (`ref` won't do if you want to store it in a local variable, because these can't be `ref`). struct BlockHead {

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/15/2015 04:51 PM, ketmar via Digitalmars-d-learn wrote: On Sun, 15 Mar 2015 16:34:14 -0700, Charles Hixson via Digitalmars-d-learn wrote: if you know the exact layouts of `spare`, you can use union for that: struct S { // ... union { ulong[61] spare; struct { int vala;

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/16/2015 09:16 AM, Charles Hixson via Digitalmars-d-learn wrote: On 03/15/2015 04:51 PM, ketmar via Digitalmars-d-learn wrote: On Sun, 15 Mar 2015 16:34:14 -0700, Charles Hixson via Digitalmars-d-learn wrote: if you know the exact layouts of `spare`, you can use union for that: struct

Re: struct / cast / ? design problem

2015-03-16 Thread ketmar via Digitalmars-d-learn
On Mon, 16 Mar 2015 12:49:40 -0700, Charles Hixson via Digitalmars-d-learn wrote: yep, you're doing it wrong, as Marc already wrote. ;-) it's not very obvious, but this line makes a copy: auto val = tst.value; there are no `ref` type in D. `ref` is modifier for function arguments, but not

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/16/2015 01:24 PM, via Digitalmars-d-learn wrote: The problem in your example is that your making a copy of the returned data. Of course any changes to that copy won't affect the original. You need to return a pointer to it (`ref` won't do if you want to store it in a local variable,

Re: struct / cast / ? design problem

2015-03-16 Thread ketmar via Digitalmars-d-learn
On Mon, 16 Mar 2015 11:18:16 -0700, Charles Hixson via Digitalmars-d-learn wrote: My current best answer is to turn the unused into a vector of bytes, and then pass that to the using routines as a ref. This still is wide open to errors at the calling end, but the BlockHead end can ensure that

Re: struct / cast / ? design problem

2015-03-16 Thread Charles Hixson via Digitalmars-d-learn
On 03/16/2015 11:55 AM, ketmar via Digitalmars-d-learn wrote: On Mon, 16 Mar 2015 11:18:16 -0700, Charles Hixson via Digitalmars-d-learn wrote: My current best answer is to turn the unused into a vector of bytes, and then pass that to the using routines as a ref. This still is wide open to

Re: struct / cast / ? design problem

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 16:34:14 -0700, Charles Hixson via Digitalmars-d-learn wrote: if you know the exact layouts of `spare`, you can use union for that: struct S { // ... union { ulong[61] spare; struct { int vala; ubyte valb; } // etc. } } and then you can use it like this:

struct / cast / ? design problem

2015-03-15 Thread Charles Hixson via Digitalmars-d-learn
I've got, say, a file header in a routine that looks like: structBlockHead { uintmagic=20150312;//block magic uintmagic2;//magic for use by the using routine uintblockSize; uintunused1; ulongunused2;