Problem: handling a function dependent on release mode.

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 20 17:56:38 PDT 2012


On Friday, July 20, 2012 23:36:58 Damian wrote:
> Trying to convert the below code to D, for the life of me I
> cannot do it :( I'm guess I need to use a template for this
> but I just cannot get my head around it. Any help please?
> 
> #ifdef SFML_DEBUG
> 
> // If in debug mode, perform a test on every call
> #define alCheck(Func) ((Func), priv::alCheckError(__FILE__,
> __LINE__))
> 
> #else
> 
> // Else, we don't add any overhead
> #define alCheck(Func) (Func)
> 
> #endif
> 
> 
> void alCheckError(const std::string& file, unsigned int line);

It is impossible to have a function which relies on -release unless you put 
all calls to it in an assertion. There is _no_ way to check whether -release 
is enabled or not.

-debug enables debug blocks:

debug
{
 //my code that runs with -debug only
}

but that's only if -debug is used. It's perfectly possible to compile with 
neither -release nor -debug. The result is that talking about "debug mode" in 
D is really confusing and inaccurate.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list