Final by default?

Michel Fortin michel.fortin at michelf.ca
Mon Mar 17 04:49:42 PDT 2014


On 2014-03-17 01:20:37 +0000, Walter Bright <newshound2 at digitalmars.com> said:

> On 3/15/2014 6:44 AM, Johannes Pfau wrote:
>> Then in cairo.d
>> version(CAIRO_HAS_PNG_SUPPORT)
>> {
>>     extern(C) int cairo_save_png(char* x);
>>     void savePNG(string x){cairo_save_png(toStringz(x))};
>> }
> 
> try adding:
> 
>    else
>    {
>         void savePNG(string x) { }
>    }
> 
> and then your users can just call savePNG without checking the version.

Adding a stub that does nothing, not even a runtime error, isn't a very 
good solution in my book. If this function call should fail, it should 
fail early and noisily.

So here's my suggestion: use a template function for the wrapper.

	extern(C) int cairo_save_png(char* x);
	void savePNG()(string x){cairo_save_png(toStringz(x));}

If you call it somewhere it and cairo_save_png was not compiled in 
Cairo, you'll get a link-time error (undefined symbol cairo_save_png). 
If you don't call savePNG anyhere there's no issue because savePNG was 
never instantiated.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list