www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - debug & optimization

reply Charles Hixson <charleshixsn earthlink.net> writes:
Would:
void    test(string s = "default message")
{ debug
   {
       .........
   } // debug
} // test

be optimized away in code that was compiled with debug turned off?

I've documented my code that this is a noop unless debug is true, but 
I'm not really sure that's correct, or whether there would be a function 
call

-- 
Charles Hixson
Jun 18 2013
next sibling parent reply Justin Whear <justin economicmodeling.com> writes:
On Tue, 18 Jun 2013 12:39:31 -0700, Charles Hixson wrote:

 Would:
 void    test(string s = "default message")
 { debug
    {
        .........
    } // debug
 } // test
 
 be optimized away in code that was compiled with debug turned off?
 
 I've documented my code that this is a noop unless debug is true, but
 I'm not really sure that's correct, or whether there would be a function
 call
A debug block works just like any other version(...) block: if the version is not set, the compiler ignores the block completely. The contents of the block are parsed (must be syntactically valid) but no semantic analysis or code-gen is performed on it, so unless the version is set, it's as if the contents of the block never existed.
Jun 20 2013
parent Justin Whear <justin economicmodeling.com> writes:
On Thu, 20 Jun 2013 22:56:08 +0000, Justin Whear wrote:

 On Tue, 18 Jun 2013 12:39:31 -0700, Charles Hixson wrote:
 
 Would:
 void    test(string s = "default message")
 { debug
    {
        .........
    } // debug
 } // test
 
 be optimized away in code that was compiled with debug turned off?
 
 I've documented my code that this is a noop unless debug is true, but
 I'm not really sure that's correct, or whether there would be a
 function call
A debug block works just like any other version(...) block: if the version is not set, the compiler ignores the block completely. The contents of the block are parsed (must be syntactically valid) but no semantic analysis or code-gen is performed on it, so unless the version is set, it's as if the contents of the block never existed.
Ah my bad, I didn't realize you were asking about the function containing the block.
Jun 20 2013
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Charles Hixson:

 I've documented my code that this is a noop unless debug is 
 true, but
 I'm not really sure that's correct, or whether there would be a 
 function call
At a low optimization level probably dmd keeps the call to the empty function. At a high optimization level the call probably is optimized away. Bye, bearophile
Jun 20 2013