Thread overview
why the name toStringz?
Oct 31, 2003
Ben Hinkle
Oct 31, 2003
J Anderson
Oct 31, 2003
Walter
Oct 31, 2003
Charles Sanders
Nov 01, 2003
Helmut Leitner
Nov 01, 2003
Ben Hinkle
Nov 01, 2003
Vathix
October 31, 2003
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


October 31, 2003
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

October 31, 2003
"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.


October 31, 2003
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
>
>


November 01, 2003

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
November 01, 2003
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
>
>


November 01, 2003
> 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];