Re: Why do I get this error when casting to an immutable or shared byRef return type?

2016-06-19 Thread ag0aep6g via Digitalmars-d-learn
On 06/19/2016 12:45 PM, Gary Willoughby wrote: On Sunday, 19 June 2016 at 10:35:59 UTC, Gary Willoughby wrote: ... A more correct example: import core.stdc.stdlib; import std.traits; ref T foo(T)() { alias Type = Unqual!(T); Type* foo = cast(Type*) malloc(Type.sizeof * 8);

Re: Why do I get this error when casting to an immutable or shared byRef return type?

2016-06-19 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 19 June 2016 at 10:45:25 UTC, Gary Willoughby wrote: On Sunday, 19 June 2016 at 10:35:59 UTC, Gary Willoughby wrote: ... A more correct example: In the second example, the problem is this: alias Type = Unqual!(T); You are declaring the function to return T, which in your

Re: Why do I get this error when casting to an immutable or shared byRef return type?

2016-06-19 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 19 June 2016 at 10:35:59 UTC, Gary Willoughby wrote: ... A more correct example: import core.stdc.stdlib; import std.traits; ref T foo(T)() { alias Type = Unqual!(T); Type* foo = cast(Type*) malloc(Type.sizeof * 8); return *foo; } void main(string[]

Why do I get this error when casting to an immutable or shared byRef return type?

2016-06-19 Thread Gary Willoughby via Digitalmars-d-learn
In the following code, the `foo` function doesn't work when casting to an immutable or shared type. Can anyone please explain what is happening here? Is there any way of returning such variables byRef from a malloc'd chunk of memory? import core.stdc.stdlib; ref T foo(T)() { int* foo