Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing slice to fixed array not working with variable offset #19571

Open
dlangBugzillaToGithub opened this issue May 28, 2019 · 4 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

Manu reported this on 2019-05-28T06:12:19Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19907

CC List

  • Nicholas Wilson

Description

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.
@dlangBugzillaToGithub
Copy link
Author

dfj1esp02 commented on 2019-05-28T06:55:51Z

Workaround: buffer[x..$][0..4]

@dlangBugzillaToGithub
Copy link
Author

turkeyman commented on 2019-05-28T07:45:33Z

Nice.

@dlangBugzillaToGithub
Copy link
Author

iamthewilsonator commented on 2019-06-10T04:53:29Z

Is the workaround sufficient to close this?

@dlangBugzillaToGithub
Copy link
Author

turkeyman commented on 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant