Comments on DMD frontend.

Leandro Lucarella llucax at gmail.com
Sun Feb 24 07:30:19 PST 2008


Janice Caron, el 24 de febrero a las 08:52 me escribiste:
> On 24/02/2008, Leandro Lucarella <llucax at gmail.com> wrote:
> >  This is really annoying and can easily be changed for something like:
> >  #if DEBUG
> >  #    define debug(...) printf(__VA_ARGS__)
> >  #else
> >  #    define debug(...)
> >  #endif
> >
> >  (I know macros with variable arguments are just in C99, but I think most
> >  compilers has a vendor-specific way of doing it)
> 
> You can do it without varags.
> 
>     #if DEBUG
>     #    define dprintf(x) printf x
>     #else
>     #    define dprintf(x)
>     #endif
> 
> So long as you're prepared to call it like this:
> 
>     dprintf(("Error on line %d",n));

Yes, but that's a little more uglier and error prone, so if DMC supports
varargs (I can't test it because I don't have Windows, and I can't find a
DMC download for Linux), I'll defenetly go with varargs.

> My favorite C trick, though, was always:
> 
>     #ifdef DEBUG
>     #    define debug
>     #else
>     #    define debug /##/
>     #endif
> 
> Then you do
> 
>     debug printf(whatever);
> 
> which resolves to
> 
>     printf(whatever);
> 
> in debug mode, but to
> 
>     // printf(whatever);

This is a clever trick but IMHO it's a little confusing too.

> in release mode. Now "debug" works almost like in D. Yes, I know,
> technically C doesn't support // comments, but I've never yet
> encountered a compiler that doesn't understand them.

That's probably because // comments are valid C99 =)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Sus descipulos se miraron, sin entender unos a otros y uno levantó su
manito y le dijo: Peperino, Peperino, soy Antonito de capital: y tengo
un salvavidas... a lo que Peperino, lo miró, lo tocó, lo frotó y lo
sanó. Y todos dijeron: ehhh! Peperino se la come! Peperino se la come!
	-- Peperino Pómoro



More information about the Digitalmars-d mailing list