Re: basic_string ctor



> They're not the same in C, which has no real concept of a string.

It most certainly does.
Admittedly it has limitations (can't have a string of '\0''s, strlen() is
O(N) not O(1), all memory managment of it is manual) but it has been like
that since the early days.

> In the (IME far more common) case where the distinction is merely an
artifact
> of C's poor string concept, I'd prefer the C++ library to simply accept 0
as
> an empty string.

It has nothin to do with C's poor string concept.
It has everything to do with the fact that NULL or 0 in pointer situations
is regarded as an invalid pointer for all types.

As shown in answer to Duane, you can make a valid pointer to an empty string
and a NULL pointer both construct a std::string as empty.

But if you fold this distinction in std::string's constructor, so NULL will
silently construct an empty std::string, then in the situation where the
pointer being NULL is an error in the program, this will silently pass over
this.

Stephen Howe


.



Relevant Pages

  • Re: How to get array size from a pointer?
    ... The function signature is given and cannot be changed, so no passing ... followed by a null string. ... assigning the integer 0 to a pointer), but by a pointer to ... the same effect as passing an empty string. ...
    (comp.lang.c)
  • Re: "Mastering C Pointers"....
    ... A pointer is a kind of variable that can "point to" some object. ... has a type (pointer to int), and a value of some kind. ... You may know that you can access these integers by using array notation ... The function will take one argument, a string, and will return the length ...
    (comp.lang.c)
  • Re: pesky Pointers !!
    ... > and the function takes it as a reference instead of a copy. ... function may access the string passed directly, ... > *px dereferences the pointer to get the value ... If pTest is a pointer-to-string, *pTest is the string it points to ...
    (alt.comp.lang.learn.c-cpp)
  • Re: strtok ( ) help
    ... > splitCommandssomehow modifying the pointer, but I HAVE to call that ... Here's an idea of how to use the strtok() function. ... don't mind trashing the contents of a string s, ... will give you a loop that extracts the tokens one at a time from s. ...
    (comp.lang.c)
  • Re: new IL: C (sort of...).
    ... C doesn't need a string type... ... variant of PL/1 which was very Pascal-ish. ... - C does implement an array declaration. ... effectively converted into a pointer that can be used with the offset ...
    (comp.lang.misc)