apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Marr <gr...@alum.wpi.edu>
Subject Re: Buckets code question
Date Wed, 11 Apr 2001 15:55:39 GMT
At 10:51 AM 04/11/2001, William A. Rowe, Jr. wrote:
>APU_DECLARE(apr_bucket *) apr_bucket_socket_create(apr_socket_t *p)
>{
>     do {
>[...]
>         return ap__b;
>     } while(0);
>}
>
>So the final While(0); is definately unreachable.  No compiler error.
>
>My only question, why do {} while(0); rather than {} ?

As Cliff said:
(to allow the macro user to place a semicolon after the macro 
invocation without causing a syntax error)

If the user did this:
if(condition)
     MACRO(params);
else
     MACRO(params);

Using {} would expand to this:
if(condition)
     {
     }
     ;
else
     {
     }
     ;

while the other form expands to this

if(condition)
     do {
     } while(0);
else
     do {
     } while(0);

which is fine.

Of course, it doesn't matter if the condition is always enclosed in 
braces, but the compiler won't enforce that, and you can end up with 
error messages that don't make sense if you don't include the braces.

-- 
Greg Marr
gregm@alum.wpi.edu
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"


Mime
View raw message