Hi,
It is good we are slowly moving to using std::string... but mixing it with char* can be tricky. In particular, I've seen several bugs recently when char* is a null pointer. You cannot initialize a std::string with a null pointer. You will get at run time:
terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid
I don't know what "best practice" is but this seems to work:
std::string my_string = c_string ? c_string : "";
You can also not compare a std::string to a null pointer.
Tav
Another thing to note is that std::string should only be used for paths. For UTF-8 strings, we should use Glib::ustring, which has a character-based index operator instead of a byte-based one.
Regards, Krzysztof
2014-02-07 13:42 GMT+01:00 Tavmjong Bah <tavmjong@...8...>:
Hi,
It is good we are slowly moving to using std::string... but mixing it with char* can be tricky. In particular, I've seen several bugs recently when char* is a null pointer. You cannot initialize a std::string with a null pointer. You will get at run time:
terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid
I don't know what "best practice" is but this seems to work:
std::string my_string = c_string ? c_string : "";
You can also not compare a std::string to a null pointer.
Tav
Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.cl... _______________________________________________ Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel
On Fri, 2014-02-07 at 15:40 +0100, Krzysztof Kosiński wrote:
Another thing to note is that std::string should only be used for paths. For UTF-8 strings, we should use Glib::ustring, which has a character-based index operator instead of a byte-based one.
This would be good info for a wiki page, but the wiki is down (again or still?). There's lots of great documentation for developers in the mailing list and I'd love to be able to formalise it somehow on the website.
Thoughts?
Martin,
participants (3)
-
Krzysztof Kosiński
-
Martin Owens
-
Tavmjong Bah