Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Program to sort three integers Date: Fri, 06 Nov 2015 15:57:24 -0800 Organization: None to speak of Lines: 28 Message-ID: References: <8dcd1ed2-2734-4cff-b013-d713a33100ed@googlegroups.com> <6260467b-092e-418c-a54e-ee34e281eef6@googlegroups.com> <70ff9ced-6acf-4e7d-bc37-d0d2078eb1a6@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="14577"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196cQCb3RROG3kb9SAmRvlY" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tRDCkg2tP6zRgwDMNrTgDg9P0h8= sha1:RGG4+rky+pO6nwK72L/bBxSnJpE= Xref: csiph.com comp.lang.c:75197 David Brown writes: [...] > To be safest, your macros can still be written in the form : > > #define reverse(a, b) \ > do { t = a; a = b; b = t; } while (0) > > Then they will work even if the brackets are omitted in the conditional. If all the statements are expression statements, as they are here, you can make the macro expand to an expression rather than to a statement, which is potentially more flexible: #define reverse(a, b) ( t = (a), (a) = (b), (b) = t ) On the other hand, you can make the type an additional argument, which precludes making the whole thing an expression: #define reverse(a, b, type) \ do { const type t = (a); (a) = (b); (b) = t; } while (0) But as you say, an inline function is probably even better. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"