This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Core dump constructing a C++ string with NULL
- From: Brian Budge <brian dot budge at gmail dot com>
- To: Tom Browder <tom dot browder at gmail dot com>
- Cc: GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 13 Jan 2011 12:04:08 -0800
- Subject: Re: Core dump constructing a C++ string with NULL
- References: <AANLkTin_hTLeBJQfTAyS_-hX4Bq4FoghFNX9tAtBpraK@mail.gmail.com>
I think that std::string can only be constructed with a valid non-zero
(including terminator) length char *.
You could do this:
char const *val = whatever;
std::string s( val ? val : "");
Brian
On Thu, Jan 13, 2011 at 11:56 AM, Tom Browder <tom.browder@gmail.com> wrote:
> It would be nice if this would construct an empty string:
>
> ?#include <string>
> ?std::string s(0);
>
> At the moment that gives a core dump.
>
> Is that defined behavior according to the standard? ?If not, what
> about a g++ enhancement?
>
> Thanks.
>
> Regards.
>
> -Tom
>
> Thomas M. Browder, Jr.
> Niceville, Florida
> USA
>