Re: [PATCH] util: Make virStringArrayHasString() const-correct

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

 



On Tue, 2016-08-16 at 18:49 +0200, Michal Privoznik wrote:
> On 16.08.2016 13:40, Andrea Bolognani wrote:
> > 
> > The first argument should be const char ** instead of
> > char **, because this is a search function and as such it
> > doesn't, and shouldn't, alter the haystack in any way.
> > 
> > This change means we no longer have to cast arrays of
> > immutable strings to arrays of mutable strings; we still
> > have to do the opposite, though, but that's reasonable.
> 
> Is it? I mean, we are restricting ourselves and compiler fails to see
> that. To me 'const char **' is more restrictive than 'char **' therefore
> there should be no typecast required. But this is the discussion I
> should have with gcc devels. For some reason, gcc does automatic
> typecasting to const just for the fist level pointers and not the second
> one. That's why compilers errors out.

The reason for this behavior is explained in the C FAQ:

  http://c-faq.com/ansi/constmismatch.html

It's unfortunate, and very annoying. But I'd rather have
to perform arguably redundant casts than being bitten by
that kind of bug down the line :)

> ACK

Pushed, thanks!

-- 
Andrea Bolognani / Red Hat / Virtualization

--
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]