qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] Re: [PATCH 02/29] Introduce QInt


From: Luiz Capitulino
Subject: [Qemu-devel] Re: [PATCH 02/29] Introduce QInt
Date: Thu, 13 Aug 2009 11:16:12 -0300

On Thu, 13 Aug 2009 16:55:50 +0300
Avi Kivity <address@hidden> wrote:

> On 08/13/2009 04:50 PM, Luiz Capitulino wrote:
> > +
> > +/**
> > + * qobject_to_qint(): Convert a QObject into a QInt
> > + */
> > +static inline QInt *qobject_to_qint(const QObject *obj)
> > +{
> > +    return container_of(obj, QInt, base);
> > +}
> > +
> >    
> 
> It's worthwhile to check the type here and return NULL if not an 
> integer.  That allows users to
> 
>     QInt *qi = qobject_to_qint(...);
> 
>     if (qi) {
>         do something
>     } else {
>         error handling
>     }
> 
> (this is equivalent to C++'s static_cast vs. dynamic_cast)

 OK.

 Note that QDict has high-level helpers like qdict_get_int()
that assumes that the stored key is a QInt.

 I was in doubt about how to fail. I chose to use assert() and
consider this a programming error.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]