digitalmars.D.bugs - [Issue 19907] New: passing slice to fixed array not working with
- d-bugmail puremagic.com (28/28) May 27 2019 https://issues.dlang.org/show_bug.cgi?id=19907
https://issues.dlang.org/show_bug.cgi?id=19907 Issue ID: 19907 Summary: passing slice to fixed array not working with variable offset Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: turkeyman gmail.com 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. --
May 27 2019