WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] debugging frustration

To: xen-devel@xxxxxxxxxxxxxxxxxxxxx
Subject: Re: [Xen-devel] debugging frustration
From: Luciano Miguel Ferreira Rocha <strange@xxxxxxxxxxxxx>
Date: Mon, 14 Feb 2005 16:14:19 +0000
Delivery-date: Mon, 14 Feb 2005 16:16:34 +0000
Envelope-to: xen+James.Bulpin@xxxxxxxxxxxx
In-reply-to: <4210BDA9.5070901@xxxxxxxxxxxxx>
List-archive: <http://sourceforge.net/mailarchive/forum.php?forum=xen-devel>
List-help: <mailto:xen-devel-request@lists.sourceforge.net?subject=help>
List-id: List for Xen developers <xen-devel.lists.sourceforge.net>
List-post: <mailto:xen-devel@lists.sourceforge.net>
List-subscribe: <https://lists.sourceforge.net/lists/listinfo/xen-devel>, <mailto:xen-devel-request@lists.sourceforge.net?subject=subscribe>
List-unsubscribe: <https://lists.sourceforge.net/lists/listinfo/xen-devel>, <mailto:xen-devel-request@lists.sourceforge.net?subject=unsubscribe>
Mail-followup-to: Luciano Miguel Ferreira Rocha <strange@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxxx
References: <6964b3969b0cbc632c2161cb16ad0e8b@xxxxxxxxxxx> <200502141424.38935.maw48@xxxxxxxxxxxx> <4210BDA9.5070901@xxxxxxxxxxxxx>
Sender: xen-devel-admin@xxxxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.4.1i
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

<Prev in Thread] Current Thread [Next in Thread>