Re: avoid extra variable during void pointer cast

2017-05-17 Thread Marco Leise via Digitalmars-d-learn
Am Mon, 15 May 2017 19:30:00 + schrieb Bauss : > pragma(inline, true); doesn't actually do what you think it does. > In lining is always done whenever possible and that only tells > the compiler to spit out an error if it can't inline it. A compiler doesn't simply inline whenever it can. A

Re: avoid extra variable during void pointer cast

2017-05-15 Thread Bauss via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:07:36 UTC, Marco Leise wrote: Am Sun, 14 May 2017 20:18:24 + schrieb Kevin Brogan : [...] No, that is not possible. An alias can only be assigned a symbol. [...] Let the compiler optimize the assignment away and don't worry much about it. Inlining also

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 22:00:58 UTC, Stanislav Blinov wrote: [...] Yep, it's an alias to template function instantiation, that is, concrete function - a symbol. Yes, my bad :( But of course, it *is* going to be called on every "dereference". GDC optimizes the call away starting at -O1,

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:55:01 UTC, ag0aep6g wrote: On 05/14/2017 11:35 PM, Moritz Maxeiner wrote: On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote: [...] T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } [...] alias _state = ptrCast!(int, state); [...] That's a prett

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:55:01 UTC, ag0aep6g wrote: On 05/14/2017 11:35 PM, Moritz Maxeiner wrote: On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote: [...] T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } [...] alias _state = ptrCast!(int, state); [...] That's a prett

Re: avoid extra variable during void pointer cast

2017-05-14 Thread ag0aep6g via Digitalmars-d-learn
On 05/14/2017 11:35 PM, Moritz Maxeiner wrote: On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote: [...] T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } [...] alias _state = ptrCast!(int, state); [...] That's a pretty cool workaround, but not an alias to the cast, but an

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote: On the point of "not possible...", "only a symbol...", etc: T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } void addInt(void* state, void* data) { alias _state = ptrCast!(int, state); alias _data = ptrCast!(int, data);

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Stanislav Blinov via Digitalmars-d-learn
On the point of "not possible...", "only a symbol...", etc: T* ptrCast(T, alias ptr)() { return cast(T*)ptr; } void addInt(void* state, void* data) { alias _state = ptrCast!(int, state); alias _data = ptrCast!(int, data); static assert(!is(typeof(_state) == int*)); static assert

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Mike B Johnson via Digitalmars-d-learn
On Sunday, 14 May 2017 at 20:18:24 UTC, Kevin Brogan wrote: I have a piece of code that takes a callback function. The callback has the signature void callback(void* state, void* data) There are several of these functions. All of them use state and data as differing types. As an example, l

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Marco Leise via Digitalmars-d-learn
Am Sun, 14 May 2017 20:18:24 + schrieb Kevin Brogan : > I have a piece of code that takes a callback function. > > The callback has the signature void callback(void* state, void* > data) > > There are several of these functions. All of them use state and > data as differing types. > > As

Re: avoid extra variable during void pointer cast

2017-05-14 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 14 May 2017 at 20:18:24 UTC, Kevin Brogan wrote: I have a piece of code that takes a callback function. The callback has the signature void callback(void* state, void* data) There are several of these functions. All of them use state and data as differing types. As an example, l