www.digitalmars.com         C & C++   DMDScript  

D - why the name toStringz?

reply "Ben Hinkle" <bhinkle4 juno.com> writes:
Why is "toStringz" called "toStringz"? I was looking for a function name
more along the lines of "toCString" or just "cstring". It is a cute pun on
"strings" and "stringz" and I guess the "z" is for "zero" and it mirrors
"toString" but overall the name is pretty obscure to me.
I can't remember the exact names of the functions that converted from Pascal
to C string I used back when the Mac was Pascal based but they seemed pretty
reasonable.
Has there been discussion of this before?
-Ben
Oct 31 2003
next sibling parent J Anderson <anderson badmama.com.au.REMOVE> writes:
Ben Hinkle wrote:

Why is "toStringz" called "toStringz"? I was looking for a function name
more along the lines of "toCString" or just "cstring". It is a cute pun on
"strings" and "stringz" and I guess the "z" is for "zero" and it mirrors
"toString" but overall the name is pretty obscure to me.
I can't remember the exact names of the functions that converted from Pascal
to C string I used back when the Mac was Pascal based but they seemed pretty
reasonable.
Has there been discussion of this before?
-Ben


  
I like the name, because it does not refer to c. Why should zero terminated strings refer to c, it's not the only language that uses them. In fact, zero terminated strings in c are just a convention (although a very common convention), not part of the language. -Anderson
Oct 31 2003
prev sibling next sibling parent "Walter" <walter digitalmars.com> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:bntnf9$2262$1 digitaldaemon.com...
 Why is "toStringz" called "toStringz"? I was looking for a function name
 more along the lines of "toCString" or just "cstring". It is a cute pun on
 "strings" and "stringz" and I guess the "z" is for "zero" and it mirrors
 "toString" but overall the name is pretty obscure to me.
 I can't remember the exact names of the functions that converted from
Pascal
 to C string I used back when the Mac was Pascal based but they seemed
pretty
 reasonable.
 Has there been discussion of this before?
 -Ben
It falls back to the ancient convention of calling a zero-terminated string ASCIZ. I always liked that, though I haven't seen anyone use that nickname for a loooong time. At one early point, the D char type was called 'ascii', but since ascii is a trademarked name, and since char morphed into being a UTF-8 type, it was dropped.
Oct 31 2003
prev sibling next sibling parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
I kind of agree, its not completely intuitive, i usually alias it to c_str
in the string module.

C

"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:bntnf9$2262$1 digitaldaemon.com...
 Why is "toStringz" called "toStringz"? I was looking for a function name
 more along the lines of "toCString" or just "cstring". It is a cute pun on
 "strings" and "stringz" and I guess the "z" is for "zero" and it mirrors
 "toString" but overall the name is pretty obscure to me.
 I can't remember the exact names of the functions that converted from
Pascal
 to C string I used back when the Mac was Pascal based but they seemed
pretty
 reasonable.
 Has there been discussion of this before?
 -Ben
Oct 31 2003
parent Helmut Leitner <helmut.leitner chello.at> writes:
Charles Sanders wrote:
 
 I kind of agree, its not completely intuitive, i usually alias it to c_str
 in the string module.
I find it entirely intuitive, for the "Z" at the end symbolizes the placement. I once built a system that supported a number of different string types in a database. The names where (IIRC): string /0 STRINGZ short SZ n string NSTRING (max 256 chars) short NS nm string NMSTRING (max 64 K chars) short MS ... There seemed nothing more natural. Such string conventions have nothing to do with a special language, so c_str just embodies a personal habit or viewpoint. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Nov 01 2003
prev sibling parent reply "Ben Hinkle" <bhinkle4 juno.com> writes:
I thought of two other points.
1) By being so close to toString one could easily believe it takes the same
inputs as toString and just returns a zero-terminated version. But as far as
I can tell one can only pass char[] to toStringz.
2) shouldn't toStringz return a D string that is zero terminated? That would
be more consistent with toString and would make the use of the word "string"
more consistent.

-Ben

"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:bntnf9$2262$1 digitaldaemon.com...
 Why is "toStringz" called "toStringz"? I was looking for a function name
 more along the lines of "toCString" or just "cstring". It is a cute pun on
 "strings" and "stringz" and I guess the "z" is for "zero" and it mirrors
 "toString" but overall the name is pretty obscure to me.
 I can't remember the exact names of the functions that converted from
Pascal
 to C string I used back when the Mac was Pascal based but they seemed
pretty
 reasonable.
 Has there been discussion of this before?
 -Ben
Nov 01 2003
parent "Vathix" <vathix dprogramming.com> writes:
 2) shouldn't toStringz return a D string that is zero terminated? That
would
 be more consistent with toString and would make the use of the word
"string"
 more consistent.
That's not bad... I do this sometimes, to make a string compatible with C and D: s = toStringz(s)[0 .. s.length];
Nov 01 2003