[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] debugging frustration



On Mon, Feb 14, 2005 at 09:03:05AM -0600, Anthony Liguori wrote:
> Mark Williamson wrote:
> 
> >>Also, is there a reason that not having DEBUG in turns dprintf into do
> >>{} while(0) instead of just turning into ""
> >>   
> >>
> The do {} while (0) idiom is commonly used in macros to protect against 
> the following.  Say you had a macro that looked like this:
> 
> #define DEBUG(a, b)  if (a > debug_level) printf(b);
> 
> If you called it like this:
> 
> if (ptr == NULL)
>   DEBUG(10, "Bad pointer");
> else
>   *ptr = 2;
> 
> What would actually happen is that the else clause would get attached to 
> the if from the DEBUG() statement and you would get very odd behavior.
> 
> Using do {} while (0) is just the common solution to this problem.  It's 
> not the only solution, but it's what most people use.

Yes, but an empty macro results in the same thing as a do {} while (0)

if (ptr == null)
    ;
else
    *ptr = 2

The only problem is when the macro has some code (AFAIK).

Regards,
Luciano Rocha


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.