[Spice-devel] [PATCH spice-streaming-agent v2 3/4] use std::string where it's easy to replace

Christophe de Dinechin cdupontd at redhat.com
Wed Feb 14 15:08:29 UTC 2018



> On 14 Feb 2018, at 15:28, Christophe Fergeau <cfergeau at redhat.com> wrote:
> 
> On Thu, Feb 08, 2018 at 08:16:37AM +0100, Christophe de Dinechin wrote:
>> Using std::string by default is *not* considered a good practice in
>> C++. The reference for C++ good practices are probably best summarized
>> by the C++ Core Guidelines:
>> https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md.
>> Regarding strings, see
>> https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rstr-zstring,
>> which specifically states this:
>> 
>> 	Don't convert a C-style string to string unless there is a reason to.
>> 
>> “abc” is a C-style string, even in C++. You should pass it around as const char *, aka czstring as long as you can. *That* is the C++ good practice AFAIK.
>> 
> 
> For maximal clarity, the link that you gave says *not* to use const char
> *, but to use czstring instead... This does not say to "pass it around
> as const char *”.

Sorry if I was not maximally clear ;-)

czstring is just a typedef in the GSL for const char *, but the gsl and czstring are not (yet) in the standard. Since we don’t use the gsl, for now we have no better than const char *.

PS: Personally, I find it a bit confusing that the Core guidelines refer to types that are not in the standard ;-D


Christophe





More information about the Spice-devel mailing list