do{..}while(0) macro substitutions

From: Yan (rottled_at_gmail.com)
Date: 12/31/04


Date: Thu, 30 Dec 2004 23:29:27 GMT

A lot of times when reading open software, i come across macros that are
defined as follows:

#define CALL_FUNCS(x) \
do { \
    func1(x); \
    func2(x); \
    func3(x); \
} while (0);

now, of course this will work but how is this any better than:

#define CALL_FUNCS(x) \
{ \
    func1(x); \
    func2(x); \
    func3(x); \
}

i can't see how the compiler can optimize (a) any better than (b) or in
any case can (b) break what (a) won't. Any input will be appreciated.

tia



Relevant Pages

  • Re: Reflections on a classic Lisp Paper
    ... lisp dialects. ... user-defined special forms - Macros, Fexprs, and Nlambda. ... compilable because the compiler just couldn't do it. ...
    (comp.lang.lisp)
  • Re: Cpp Considered Harmful
    ... > However, in either case, assertions are invaluable in making certain ... because we now have our own cpp ... > macros, we can use several different compilers and have our system ... > built into the compiler. ...
    (comp.lang.cpp)
  • Re: Doing mini-languages in CL
    ... > Thats it in a nutshell. ... I think the detail to note is that the Macro facility is a Compiler ... simply put you may well be able to leverage CL macros in building your ...
    (comp.lang.lisp)
  • Re: Why doesnt Lisp automatically differentiate functions and macros?
    ... what stops a Lisp machine from figuring automatically which ... small subset of things macros can do that you are thinking is all they can ... This requires the compiler to know how to do things. ... things that the compiler writer didn't think to, ...
    (comp.lang.lisp)
  • Re: Doing mini-languages in CL
    ... "Will Hartung" writes: ... >> address fixup grunt work to it. ... > Your compiler will already take S-exprs, but there's nothing that says those ... and you find you won't necessarily need macros. ...
    (comp.lang.lisp)