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

Re: [libvirt] [PATCH v3 1/4] iptablesFormatNetwork(): constify target of "netaddr" parameter



Il 24/09/2013 10:46, Laine Stump ha scritto:
> On 09/23/2013 08:03 PM, Laszlo Ersek wrote:
> > ... and adapt functions that would cast away the new const qualifier.
> >
> > Given
> >
> >   typedef virSocketAddr *virSocketAddrPtr;
> >
> > Compare the parse trees of the following two declarations:
> >
> >   (a) const virSocketAddrPtr  addr;
> >   (b) const virSocketAddr    *addr;
> 
> Umm.. Eric? A little help? :-)

Heh :)

In more layman terms, you can read types out in English like this:

(1) read the type from right to the left

(2) if "const" is the first token, read it as "that is constant" and
associate it to the closest type.  Alternatively, move such a "const"
right but no further than the first *.

(3) if "const" is anywhere else, read it as "constant"

So:

const virSocketAddrPtr addr
      ("addr is a virSocketAddrPtr that is constant")
-> virSocketAddrPtr const addr
      ("addr is a constant virSocketAddrPtr")
-> virSocketAddr * const addr
      ("addr is a constant pointer to virSocketAddr

const virSocketAddr *addr
      ("addr is a pointer to a virSocketAddr that is constant")
-> virSocketAddr const *addr
      ("addr is a pointer to a constant virSocketAddr")

Laszlo, correct me if I'm wrong.

I suspect that forbidding const.*Ptr in "make syntax-check" wouldn't be
a bad idea.

Paolo


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