Consider this function:
void fun(ref char[4]);
You can call it like this:
char[20] buffer;
// pass a slice of buffer as the static array
fun(buffer[10 .. 10 + 4]);
That works as expected, but this doesn't work:
// pass a slice of buffer as the static array with variable offset
int x = 10;
fun(buffer[x .. x + 4]);
This is pretty annoying... only workaround some hideous casting:
fun(*cast(char[4]*)(buffer.ptr + x));
Would be nice for the prior expression to work in @safe code.
Comment #1 by dfj1esp02 — 2019-05-28T06:55:51Z
Workaround: buffer[x..$][0..4]
Comment #2 by turkeyman — 2019-05-28T07:45:33Z
Nice.
Comment #3 by iamthewilsonator — 2019-06-10T04:53:29Z
Is the workaround sufficient to close this?
Comment #4 by turkeyman — 2019-06-10T05:04:51Z
I don't think it should be closed, seems like a legit issue to me...
Workaround is workable though, so it's not a priority.
Comment #5 by robert.schadek — 2024-12-13T19:03:33Z