I've found the first thing in D that REALLY got on my nerves

mike vertex at gmx.at
Thu Sep 7 18:03:40 PDT 2006


Hi!

Maybe you read my last posts about VST plugins ... just to clear that up,  
I don't want to leave wrong info here: They've got a C interface, so all  
my writing about linking C++ was bs. Just in case anybody wants to do some  
VST development in D. Go ahead, no problem with D either way (host or  
plugin - both works when one converts the SDK files to D). I'm already  
happily loading VST plugins and toying aroung with them.

Anyway, I've found something annoying, nothing really bad, but just  
terribly annoying for a medium-level coder like me.

 From my code:

' void *proc = GetProcAddress(hlib, toStringz("main"));
' if(proc is null)
' {
'     [snip]
' }
'
' auto getNewPluginInstance = cast(mainFunc)proc;
'
' // get new instance
' AEffect *newInstance = null;
' newInstance = getNewPluginInstance(&audioMaster);

That works. Why? Because:

' extern (C)
' {
'     typedef AEffect *function(audioMasterCallback) mainFunc;
'     [snip]
' }

There's something that didn't work (Access violation when calling  
getNewPluginInstance) and it cost me hours of debugging and trying out  
insanely unlogical things, until I had the idea to define mainFunc as a  
type. Good thing is I found a lot of bugs in advance. Well, that's how it  
originally was:

' auto getNewPluginInstance = cast(AEffect  
*function(audioMasterCallback))proc;

Without the typdef. Access violation, because getNewPluginInstance has D  
linkage. And there's no way to cast that void * pointer to a C function.  
Defining the mainFunc type solves this.

Just wanted to point that out. After half a year with D - this was the  
first time I ever got angry at this language.

' auto getNewPluginInstance = cast(extern (C) AEffect  
*function(audioMasterCallback))proc;

That would be a logical and intuitive thing - at least for me. If you have  
a call-once-forget-afterwards function with C linkage you shouldn't be  
forced to define a type. I even had the whole module extern (C). Didn't  
work.

-Mike

-- 
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list