Re: Is there a way to slice non-array type in @safe?

2019-07-12 Thread Stefanos Baziotis via Digitalmars-d-learn
Thank you all for your responses. I understand that the compiler can't ensure @safe and @trusted is needed.. I'm not familiar though with all aspects of D and thought I might have missed something. On Friday, 12 July 2019 at 01:24:06 UTC, Jonathan M Davis wrote: BTW, if you're implementing

Re: Is there a way to slice non-array type in @safe?

2019-07-12 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 11 July 2019 at 19:35:50 UTC, Stefanos Baziotis wrote: On Thursday, 11 July 2019 at 18:46:57 UTC, Paul Backus wrote: Casting from one type of pointer to another and slicing a pointer are both @system, by design. Yes, I'm aware, there are no pointers in the code. The pointer

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 11, 2019 1:44:51 PM MDT Stefanos Baziotis via Digitalmars- d-learn wrote: > On Thursday, 11 July 2019 at 19:37:38 UTC, Nathan S. wrote: > > If you know that what you're doing cannot result in memory > > corruption but the compiler cannot automatically infer @safe, > > it is

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 11 July 2019 at 19:44:51 UTC, Stefanos Baziotis wrote: On Thursday, 11 July 2019 at 19:37:38 UTC, Nathan S. wrote: If you know that what you're doing cannot result in memory corruption but the compiler cannot automatically infer @safe, it is appropriate to use @trusted. (For

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Stefanos Baziotis via Digitalmars-d-learn
On Thursday, 11 July 2019 at 19:37:38 UTC, Nathan S. wrote: If you know that what you're doing cannot result in memory corruption but the compiler cannot automatically infer @safe, it is appropriate to use @trusted. (For this case make sure you're not returning the byte slices, since if the

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Nathan S. via Digitalmars-d-learn
On Thursday, 11 July 2019 at 16:31:58 UTC, Stefanos Baziotis wrote: I searched the forum but did not find something. I want to do this: int foo(T)(ref T s1, ref T s2) { const byte[] s1b = (cast(const(byte)*))[0 .. T.sizeof]; const byte[] s2b = (cast(const(byte)*))[0 .. T.sizeof]; }

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Stefanos Baziotis via Digitalmars-d-learn
On Thursday, 11 July 2019 at 18:46:57 UTC, Paul Backus wrote: Casting from one type of pointer to another and slicing a pointer are both @system, by design. Yes, I'm aware, there are no pointers in the code. The pointer was used here because it was the only way to solve the problem (but not

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Stefanos Baziotis via Digitalmars-d-learn
On Thursday, 11 July 2019 at 18:46:57 UTC, Paul Backus wrote: What's the actual problem you're trying to solve? There may be a different way to do it that's @safe. I hope I answered the "what". In case the "why" helps too, it is because I'm implementing memcmp().

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 11 July 2019 at 16:31:58 UTC, Stefanos Baziotis wrote: I searched the forum but did not find something. I want to do this: int foo(T)(ref T s1, ref T s2) { const byte[] s1b = (cast(const(byte)*))[0 .. T.sizeof]; const byte[] s2b = (cast(const(byte)*))[0 .. T.sizeof]; }