View mode: basic / threaded / horizontal-split · Log in · Help
March 20, 2008
passing all writefln arguments
I'm trying to make my own little debug_writefln which only prints when I set 
my DEBUGG to true.

void dWritefln(...){
  if(DEBUGG==true) writefln( ? );
}

What should I place there to make this work, or should I approuch this 
wholly differently?
March 20, 2008
Re: passing all writefln arguments
Saaa wrote:
> I'm trying to make my own little debug_writefln which only prints when I set 
> my DEBUGG to true.
> 
> void dWritefln(...){
>    if(DEBUGG==true) writefln( ? );
> }
> 
> What should I place there to make this work, or should I approuch this 
> wholly differently? 
> 
> 

Easier if you turn it inside out.

debug(DEBUGG) {
   alias writefln dWritefln;
}
else {
   void dWritefln(...) {}
}

--bb
March 20, 2008
Re: passing all writefln arguments
Thanks,

As I think that changing a variable is easier than changing the compiler 
line I went with:

const bool DEBUGG=false;

static if (DEBUGG == true) {
alias writefln dWritefln;
}
else {
void dWritefln(...) {}
}

Will dWritefln(..){} compile to 'nothing'?
I mean, will calling dWritefln when DEBUGG=false take no cpu tick (does the 
compiler see that it does nothing)?


>
> Easier if you turn it inside out.
>
> debug(DEBUGG) {
>    alias writefln dWritefln;
> }
> else {
>    void dWritefln(...) {}
> }
>
> --bb
March 20, 2008
Re: passing all writefln arguments
Saaa wrote:
> Thanks,
> 
> As I think that changing a variable is easier than changing the compiler 
> line I went with:
> 
> const bool DEBUGG=false;
> 
> static if (DEBUGG == true) {
>  alias writefln dWritefln;
> }
> else {
>  void dWritefln(...) {}
> }

I think you can set debug versions inside a file too.  That way you can 
have the best of both worlds.  Turn it on from the command line, or by 
modifying the file.

debug = DEBUGG;

debug(DEBUGG) {
 alias writefln dWritefln;
}
else {
 void dWritefln(...) {}
}

... at least that works with 'version'.  Not sure if it works with debug 
too.  (If it doesn't I'll file a bug about the inconsistency with 
'version'.)

> Will dWritefln(..){} compile to 'nothing'?
> I mean, will calling dWritefln when DEBUGG=false take no cpu tick 
(does the
> compiler see that it does nothing)?


Yes.  See thread entitled "debug()" over in digitalmars.D.
digitalmars.com digitalmars.D:66826
digitalmars.com digitalmars.D:66827

But that may only be with -inline.  Not sure what flags Jarrett used 
when he ran the test.

--bb
March 21, 2008
Re: passing all writefln arguments
Seems to work, thanks.


> Saaa wrote:
>> Thanks,
>>
>> As I think that changing a variable is easier than changing the compiler 
>> line I went with:
>>
>> const bool DEBUGG=false;
>>
>> static if (DEBUGG == true) {
>>  alias writefln dWritefln;
>> }
>> else {
>>  void dWritefln(...) {}
>> }
>
> I think you can set debug versions inside a file too.  That way you can 
> have the best of both worlds.  Turn it on from the command line, or by 
> modifying the file.
>
> debug = DEBUGG;
>
> debug(DEBUGG) {
>  alias writefln dWritefln;
> }
> else {
>  void dWritefln(...) {}
> }
>
> ... at least that works with 'version'.  Not sure if it works with debug 
> too.  (If it doesn't I'll file a bug about the inconsistency with 
> 'version'.)
>
>> Will dWritefln(..){} compile to 'nothing'?
> > I mean, will calling dWritefln when DEBUGG=false take no cpu tick
> (does the
> > compiler see that it does nothing)?
>
>
> Yes.  See thread entitled "debug()" over in digitalmars.D.
> digitalmars.com digitalmars.D:66826
> digitalmars.com digitalmars.D:66827
>
> But that may only be with -inline.  Not sure what flags Jarrett used when 
> he ran the test.
>
> --bb
Top | Discussion index | About this forum | D home