Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
I am a C++ game developer and I want to give it a try. It seems "this" in Dlang is a reference instead of pointer. How can I pass it as void *? void foo(void *); class Pizza { public: this() { Pizza newone = this; // works but newone is actually not this pizza. foo(

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote: I am a C++ game developer and I want to give it a try. It seems "this" in Dlang is a reference instead of pointer. How can I pass it as void *? void foo(void *);

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:14:32 UTC, Stefan Koch wrote: On Wednesday, 22 November 2017 at 15:11:08 UTC, Tim Hsu wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch &this will do. I've tried it in the first place. ... Error: this is not an lvalue In that case cas

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: &this will do. Even if it were an lvalue, that would be the address of a local. You should basically NEVER do that with D classes. Just `cast(void*) this`

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:27:27 UTC, Dukc wrote: On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: &this will do. Even if it were an lvalue, that would be the address of a local. You should basic

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:36:22 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote: It seems in D, reference has its own address, am I right? unlike c++ The local variable does have its own address. Do not take its address - avoid &this or &obje

glfwSetDropCallback undefined symbol

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
DCD and DMD says that the symbol is undefined! However, I look into derelichtGLFW3. It has this symbol defined! It looks like a bug for me!

Avoiding GC in D and code consistancy

2017-12-30 Thread Tim Hsu via Digitalmars-d-learn
I came from C++ looking forward to D. Some languages require programmers to use GC all the time. However, A lot of time we don't really need GC especially when the time of destruction is deterministic in compile time. I found that struct in D is allocate on stack by default. And we can use sc

Re: Avoiding GC in D and code consistancy

2017-12-31 Thread Tim Hsu via Digitalmars-d-learn
On Sunday, 31 December 2017 at 07:32:50 UTC, Ali Çehreli wrote: On 12/30/2017 11:16 PM, Tim Hsu wrote: > Struct version of Vector3f can't derive toString > method. writeln() prints unformated struct members. I know I can use > helper function here. But is there any other way? The normal way tha

Efficient way to pass struct as parameter

2018-01-02 Thread Tim Hsu via Digitalmars-d-learn
I am creating Vector3 structure. I use struct to avoid GC. However, struct will be copied when passed as parameter to function struct Ray { Vector3f origin; Vector3f dir; @nogc @system this(Vector3f *origin, Vector3f *dir) { this.origin = *origin; this.dir = *d

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Tim Hsu via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 22:49:20 UTC, Adam D. Ruppe wrote: On Tuesday, 2 January 2018 at 22:17:14 UTC, Johan Engelen wrote: Pass the Vector3f by value. This is very frequently the correct answer to these questions! Never assume ref is faster if speed matters - it may not be. However s