Final by default?

Johannes Pfau nospam at example.com
Sat Mar 15 06:44:52 PDT 2014


Am Fri, 14 Mar 2014 10:53:59 -0700
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 3/14/2014 10:26 AM, Johannes Pfau wrote:
> > I use manifest constants instead of version identifiers as well. If
> > a version identifier affects the public API/ABI of a library, then
> > the library and all code using the library always have to be
> > compiled with the same version switches(inlining and templates make
> > this an even bigger problem). This is not only inconvenient, it's
> > also easy to think of examples where the problem will only show up
> > as crashes at runtime. The only reason why that's not an issue in
> > phobos/druntime is that we only use compiler defined versions
> > there, but user defined versions are almost unusable.
> 
> Use this method:
> 
> 
>      --------
>      import wackyfunctionality;
>      ...
>      WackyFunction();
>      --------
>      module wackyfunctionality;
> 
>      void WackyFunction() {
>          version (Linux)
>            SomeWackyFunction();
>          else version (OSX)
>              SomeWackyFunction();
>          else
>              ... workaround ...
>      }
>      --------

I meant really 'custom versions', not OS-related. For example cairoD
wraps the cairo C library. cairo can be compiled without or with PNG
support. Historically cairoD used version(CAIRO_HAS_PNG_SUPPORT) for
this.

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))};
}

now I have to use version=CAIRO_HAS_PNG_SUPPORT when compiling cairoD,
but every user of cairoD also has to use version=CAIRO_HAS_PNG_SUPPORT
or the compiler will hide the savePNG functions. There are also
examples where not using the same version= switches causes runtime
crashes.

Compiler defined version(linux, OSX) are explicitly not affected by
this issue as they are always defined by the compiler for all modules.


More information about the Digitalmars-d mailing list