Re: Problems with function as parameter

2017-09-22 Thread user1234 via Digitalmars-d-learn
On Friday, 22 September 2017 at 04:32:08 UTC, Josh wrote: As an aside, in that doc it says "The .funcptr property of a delegate will return the function pointer value as a function type". So I also tried Mix_ChannelFinished((&channelDone).funcptr); and this compiled, but caused a segfault when

Re: Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
On Friday, 22 September 2017 at 03:26:36 UTC, Mike Parker wrote: On Friday, 22 September 2017 at 02:22:46 UTC, Josh wrote: src\mixer.d(80,22): Error: function pointer Mix_ChannelFinished (extern (C) void function(int channel)) is not callable using argument types (extern (C) void delegate(i

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:32:56 UTC, Josh wrote: Why should the binding force nothrow? I don't understand why you HAVE to not throw exceptions. Is it because of the C -> D aspect? Yes, it's because D exceptions are not guaranteed to propagate through the C callstack. It works on som

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:32:56 UTC, Josh wrote: Why should the binding force nothrow? I don't understand why you HAVE to not throw exceptions. Is it because of the C -> D aspect? Yes, it's because D exceptions are not guaranteed to propagate through the C callstack. It works on som

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:22:46 UTC, Josh wrote: src\mixer.d(80,22): Error: function pointer Mix_ChannelFinished (extern (C) void function(int channel)) is not callable using argument types (extern (C) void delegate(int channel)) Code: void unmuteAfterPlaySound() { Mix_Chan

Re: Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:18:34 UTC, Mike Parker wrote: On Thursday, 21 September 2017 at 22:05:22 UTC, Matt Jones wrote: On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've

Re: Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
On Thursday, 21 September 2017 at 22:05:22 UTC, Matt Jones wrote: On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just m

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:18:34 UTC, Mike Parker wrote: and use & to reference the function instead of calling it: Mix_ChannelFinished(&channelDone); To expand on this, D allows functions to be called without parentheses. `channelDone` is actually a function call, whereas in C, it

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 21 September 2017 at 22:05:22 UTC, Matt Jones wrote: On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just m

Re: Problems with function as parameter

2017-09-21 Thread Matt Jones via Digitalmars-d-learn
On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just making a minor mistake somewhere. [...] Make it a C function, n

Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just making a minor mistake somewhere. The C SDL docs say: // make a channelDo