httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryan Bloom <...@raleigh.ibm.com>
Subject Re: cvs commit: apache-2.0/src/lib/apr/network_io/unix networkio.h sockets.c sockopt.c
Date Mon, 18 Oct 1999 16:38:21 GMT

Just to clarify.  I'm not going to fix this.  I would rather do this "the
right way", then work on a method I think is a dead end.  If somebody
wants to fix the macros, go ahead, but I have decided to write new
functions to handle the non-thread safe functions, rather than try locking
them.

Ryan

On Mon, 18 Oct 1999, Dean Gaudet wrote:

> fwiw, i prefer "do { stuff } while (0)" ... and that's the technique
> currently in use in various places within apache.
> 
> Dean
> 
> On Sat, 16 Oct 1999, Greg Stein wrote:
> 
> > Manoj Kasichainula wrote:
> > > 
> > > On Sat, Oct 16, 1999 at 01:38:45PM -0700, Greg Stein wrote:
> > > > There are a couple idioms for doing "statement" macros that I've seen:
> > > >
> > > > #define FOO(x)   if (1) { do_your_stuff(x); } else
> > > > #define BAR(x)   do { do_your_stuff(x); } while (0)
> > > 
> > > I've generally used:
> > > 
> > > #define SHMUP(x) {do_your_stuff(x);}
> > > 
> > > Do some compilers not allow bare braced statement blocks?
> > 
> > Compilers will allow that, but it still doesn't bind properly. Look at
> > the following:
> > 
> >   if (foo)
> >     SHMUP(bar);
> >   else
> >     baz;
> > 
> > This would expand to:
> > 
> >   if (foo)
> >     {do_your_stuff(bar);};
> >   else
> >     baz;
> > 
> > Note the extra semicolon. However, if you use the approach that I
> > suggested, then you end up with:
> > 
> >     if (1) { do_your_stuff(x); } else ;
> > 
> > The "else" statement block is a single empty statement -- the semicolon.
> > Therefore, it completes the (inner) if/else statement. The inner if/else
> > is the "if" statement, while "baz;" is the "else" statement.
> > 
> > The issue generally boils down to people putting a semicolon after a
> > macro that looks like a function. This is usually for a few reasons:
> > habit, style, and auto-indent. Your form would be fine without the
> > semicolon and Ryan's would, too (except for the multi-statement things;
> > those would still break in certain if/else scenarios). Because of the
> > habit/style/autoindent issue, though, I strongly urge the use of the
> > if/do idioms in any macro that acts as a statement (rather than an
> > expression).
> > 
> > Cheers,
> > -g
> > 
> > --
> > Greg Stein, http://www.lyra.org/
> > 
> 

_______________________________________________________________________
Ryan Bloom		rbb@raleigh.ibm.com
4205 S Miami Blvd	
RTP, NC 27709		It's a beautiful sight to see good dancers 
			doing simple steps.  It's a painful sight to
			see beginners doing complicated patterns.	


Mime
View raw message