On 2016-09-07 15:41:03 -0500, Derek Martin wrote:
> On Wed, Sep 07, 2016 at 09:10:09AM -0500, Derek Martin wrote:
> > Like I said, I'm familiar with the do {} while (0) construct, but I
> > could swear I ran into an odd case where it caused some sort of
> > problem...  
> 
> There are several possibilities here.  There are probably others, but
> I can think of two:
> 
> Since it's a while loop, it may interfere with continue/break.  This
> is mostly an issue when the macro is intended to be able to take a
> block of code as its argument... which I'll agree is rare and should
> be avoided (though as I said, I feel that way about macros in
> general).

That would be very ugly, unreadable code.

> Another case is where you actually want the do {} while structure, but
> you want the while to be terminated by a macro argument.  A simple
> example:
> 
> #define FOO(A, I) do { my_func((A), (I)) } while ((I))

My point was to avoid something like

#define FOO(A, I) { ... }

in which case, one generally adds do ... while (0).
I have not suggested to use another form like the one you give.

-- 
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to