Re: strange output



pete wrote:
CBFalconer wrote:
Frederick Gotham wrote:
Ancient_Hacker posted:

You should make that a block of statements by putting {}'s around
the whole macro:

#define swap(a,b) { ..... }

Either:

#define swap(a,b) do {temp=(a); (a)=(b); (b)=temp;} while (0)

Or:

#define swap(a,b) (temp=(a),(a)=(b),(void)(b)=temp)

No. Only the do while (0) method will work in all circumstances.
With the braces you will get errors with:

if (condition) swap(x, y);

because of the terminal semicolon.

I disagree.
There's nothing wrong with:

if (condition) (temp=(a),(a)=(b),(void)(b)=temp);

You never follow an "if" with an "else"?

--
Chuck F (cbfalconer@xxxxxxxxx) (cbfalconer@xxxxxxxxxxxxx)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE maineline address!

.



Relevant Pages

  • Re: strange output
    ... Frederick Gotham wrote: ... the whole macro: ... With the braces you will get errors with: ... USE maineline address! ...
    (comp.lang.c)
  • RE: Working out first and last column and row in a range
    ... Pete ... > If Not Intersect, Target) Is Nothing Then ... but it's a bit clumsy and my aim is to base the macro around the ... >> Private Sub Worksheet_Change ...
    (microsoft.public.excel.programming)
  • Re: braces needed?
    ... > written macros particularly debug ones or ones requiring a local variable ... - the person who wrote "if (blah) MACRO()" should have been more awake ... I would not want to impose braces on all my code in order to avoid ...
    (comp.lang.cpp)
  • Re: Style isnt always religious
    ... >> parenthesis following the function parameters. ... >> braces are placed in K&R, I suspect they would have put braces ... > many programmers, and yes, it was fully customizable, you could ... > modifying the 'routines' macro to support your particular style. ...
    (comp.lang.c)
  • Re: Text. Replacment.Text
    ... PETE which is a horses name. ... I have two paragraphs of ... >> see i have put in 2 text, Replacement.Text in a macro. ...
    (microsoft.public.word.newusers)