Comments on DMD frontend.

Janice Caron caron800 at googlemail.com
Sun Feb 24 00:52:53 PST 2008


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

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

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.

(I still have to write C sometimes, professionally).

I don't care what language the D compiler is written in, as long as it
works. (Although now that D1 is stable, it would be quite cool to
rewrite it in that).



More information about the Digitalmars-d mailing list