Re: strange output
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 29 Aug 2006 20:23:38 GMT
In article <44F49C75.8F90E33B@xxxxxxxxx>,
CBFalconer <cbfalconer@xxxxxxxxxxxxx> wrote:
#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.
You get a problem with the braces, but not with the parenthesised
version.
I disagree.
There's nothing wrong with:
if (condition) (temp=(a),(a)=(b),(void)(b)=temp);
True.
You never follow an "if" with an "else"?
The parenthesised version, with a semicolon, is fine in that case.
The do { } version has the advantage that you can include declarations.
-- Richard
.
- References:
- strange output
- From: dis_is_eagle
- Re: strange output
- From: CBFalconer
- Re: strange output
- From: pete
- Re: strange output
- From: CBFalconer
- strange output
- Prev by Date: Re: OT/drift: when is a RAMdisk an appropriate solution
- Next by Date: Re: Buffer or Realloc?
- Previous by thread: Re: strange output
- Next by thread: Re: strange output
- Index(es):
Relevant Pages
|