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
{
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;
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
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
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,
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
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
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:
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;