June 06, 2004
It would appear that a function which requires a static array (for example std.md5.sum) cannot be passed a reference

.. even though the manaul says: "When passing a static array to a function, the result, although declared as a static array, will actually be a reference to a static array".

In other words, if you pass in a static array, it gets converted to a reference. But if you try to pass in a reference directly, you can't.

This is kinda curious. I had to work around this one. My workaround consisted of declaring a static array (on the stack), passing that to std.md5.sum, and then COPYING the result into the dynamic array where I actually wanted it (before the function returned and the stack disappeared).

If the function expects a reference, why can't we pass one? Is there ANY WAY of casting a dynamic array to make it look like a reference to a static array?

Arcane Jill


June 07, 2004
I redirect this message into the newsgroup for bugs.

Problem: the function requieres a ubyte[16]. When trying to pass a ubyte* (technically feasible), one gets "cannot implicitly convert ubyte* to ubyte[16]". When trying an explicit cast, one gets "e2ir: cannot cast from ubyte[] to ubyte[16]" or "e2ir: cannot cast from ubyte* to ubyte[16]"

Test case attached.

One possible workaround would be to change the library function to accept a dynamic array and assert on the length of it - it should also make passing static arrays possible.

-eye

Arcane Jill schrieb:

> It would appear that a function which requires a static array (for example std.md5.sum) cannot be passed a reference
> 
> .. even though the manaul says: "When passing a static array to a function, the result, although declared as a static array, will actually be a reference to a static array".
> 
> In other words, if you pass in a static array, it gets converted to a reference. But if you try to pass in a reference directly, you can't.
> 
> This is kinda curious. I had to work around this one. My workaround consisted of declaring a static array (on the stack), passing that to std.md5.sum, and then COPYING the result into the dynamic array where I actually wanted it (before the function returned and the stack disappeared).
> 
> If the function expects a reference, why can't we pass one? Is there ANY WAY of casting a dynamic array to make it look like a reference to a static array?
> 
> Arcane Jill
> 
>