Function prototype + definition in the same file

Jesse Phillips Jessekphillips+D at gmail.com
Tue Sep 25 16:05:48 PDT 2012


On Tuesday, 25 September 2012 at 11:52:38 UTC, Manu wrote:
> So I have this recurring pattern, it's really starting to annoy 
> me.
> It stems from the fact that a function prototype and the 
> definition can not
> appear in the same file in D (as it can in C/C++)
> [...]
> Go on, tear me apart... :)

I'm not sure I understand what benefit you are giving, I'll 
explain a situation I went through.

tldr: I like having a clean "header" file for static linking. It 
would be nice to build off that to dynamically link.

I wanted to load up a DLL (C++ with C interface). Found this 
nifty file on stackoverflow

http://stackoverflow.com/questions/3818229/loading-plugins-dlls-on-the-fly

Didn't want to write all those mixins myself. I already had the 
"header" file for my DLL and didn't want to write all those 
mixins.

I created an array with all the function names, then created a 
function which took iterated this array and asked for the 
function type as I'd imported the "header."

I ran into a bunch of runtime errors with this setup, probably 
didn't like the duplication of function names. Or something 
completely different.

Finally I went to static linking. Since I had a nice clean header 
I didn't need to do anything fancy, pragma(lib) my .lib file and 
disable the defFunctions mixin.


More information about the Digitalmars-d mailing list