Problems with function as parameter

Josh moonburntm at gmail.com
Fri Sep 22 02:22:46 UTC 2017


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 making a 
>> minor mistake somewhere.
>>
>> [...]
>
> Make it a C function, not a D function:
>
> extern (C) void channelDone(int channel)
> {
> 	unmuteMusic();
> }
>
> and use & to reference the function instead of calling it:
>
> Mix_ChannelFinished(&channelDone);

Thanks for the help, but when I try that, I get:

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_ChannelFinished(&channelDone);
}

extern (C) void channelDone(int channel)
{
	unmuteMusic();
}


More information about the Digitalmars-d-learn mailing list