Re: strange output
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Tue, 29 Aug 2006 15:58:45 -0400
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!
.
- Follow-Ups:
- Re: strange output
- From: Clark S. Cox III
- Re: strange output
- From: Richard Tobin
- Re: strange output
- References:
- strange output
- From: dis_is_eagle
- Re: strange output
- From: Ancient_Hacker
- Re: strange output
- From: Frederick Gotham
- Re: strange output
- From: CBFalconer
- Re: strange output
- From: pete
- strange output
- Prev by Date: Re: Hi a strange code ....
- Next by Date: Re: OT/drift: when is a RAMdisk an appropriate solution
- Previous by thread: Re: strange output
- Next by thread: Re: strange output
- Index(es):
Relevant Pages
|
|