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

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

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]