Re: Alternatives to #define?

From: Alf P. Steinbach (alfps_at_start.no)
Date: 07/04/04


Date: Sun, 04 Jul 2004 18:27:58 GMT


* Rolf Magnus:
> Alf P. Steinbach wrote:
>
> > * Rolf Magnus:
> >> Alf P. Steinbach wrote:
> >>
> >> > * Rolf Magnus:
> >> >>
> >> >> #define DO_STUFF do { doThis(); doThat(); } while(false)
> >> >
> >> > Unfortunately that may cause a warning with too "helpful" compilers
> >> > such as Visual C++.
> >> >
> >> > Try instead
> >> >
> >> > #define DO_STUFF for(;;){ doThis; doThat(); break; }
> >>
> >> Hmm, what would you gain with that for loop?
> >
> > See above.
>
> No, I mean what you gain compared to just:
>
> #define DO_STUFF() { doThis(); doThat(); }
>

Uhm, see my reply to Rob Williscroft. I was wrong. And the extreme
irony is that I've always used do-while for such things precisely
because a simple block won't do wrt. semicolon syntax, and done my best
to teach that technique to others (since you can read Norwegian as well
as C++ code I can offer an example of such teaching, namely the XASSERT
macro in <url: http://home.no.net/dubjai/03/index.html#cpputil>,
presumably some Googling on newsgroup posting would give more examples).

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Relevant Pages

  • Re: Combinatorial Problem
    ... Alf P. Steinbach wrote: ... You're wasting people's time. ... What is the most annoying thing on usenet and in e-mail? ...
    (comp.programming)
  • Re: Is Paulis repulsive force fundamental?
    ... > alfps@start.no (Alf P. Steinbach) wrote in message ... >> The trick to keeping 4 fundamental forces is to deny that other forces ...
    (sci.physics.research)
  • Re: When a default constructor necessary?
    ... Heh. ... I don't know whether the Holy Standard covers this situation ...
    (comp.lang.cpp)
  • Re: Calling COM functions using IDispatch->Invoke(...
    ... Alf P. Steinbach: ... But it also fails, could you please check out what I’m doing wrong: ... Because it messes up the order in which people normally read text. ...
    (microsoft.public.vc.mfc)
  • Re: Constant variable
    ... But does not matter here. ... You undermined the security checking of the compiler by making a constant ... This leads - as Alf Steinbach mentioned correctly - to undefined ...
    (comp.lang.cpp)