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

Erik Skultety eskultet at redhat.com
Wed Aug 17 08:22:46 UTC 2016


On 17/08/16 09:56, Andrea Bolognani wrote:
> On Tue, 2016-08-16 at 22:31 +0200, Martin Kletzander wrote:
>>>>> 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
>>  
>> Just FYI, so that you know why adding more consts (even to sensible
>> places) doesn't help in C, I found the answer to my question on stack
>> overflow [1] very satisfactory and explanatory.
> 
> So the solution is simple: rewrite all of libvirt in C++! ;)
> 
> -- 
> Andrea Bolognani / Red Hat / Virtualization
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
> 

Patches are welcome ;)...oh, wait... Or we could make a "libvirt
rationale" and state that some char ** arrays are meant to be constant
in a textual manner :).

Erik

PS: hopefully nobody took that one seriously.




More information about the libvir-list mailing list