What's going on here?

Manu turkeyman at gmail.com
Thu Jan 9 21:08:04 PST 2014


So I'm interacting with C (although it works the same in D), I call a
function that returns a pointer, and gives the size through an out arg:
  ubyte* test(size_t* ptr)
  {
*ptr = 100;
return cast(ubyte*)1234;
  }


And call it, but immediately use the size argument to slice a range:
  size_t size;
  ubyte[] t = test(&size)[0..size];

t is null.

If I do this, it works:
  size_t size;
  ubyte* pt = test(&size);
  ubyte[] t = pt[0..size];

Why should I need that extra line?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140110/aabbf6d1/attachment-0001.html>


More information about the Digitalmars-d mailing list