www.digitalmars.com         C & C++   DMDScript  

D - parameter decorator for zero-terminated strings

reply "Matthew Wilson" <dmd synesis.com.au> writes:
I'd really like a parameter decorator that caused either automatic
conversion of a character (char or wchar) array to a zero-terminated string,
a la toStringz, or, preferably, requires a cast (thus causing the programmer
to be mindful of the need to null-terminate).

In fact, I'd quite like any function taking char/wchar* requires an explicit
cast from char/wchar[]. Is there a reason why this is not required now?
Sep 17 2003
parent reply "Philippe Mori" <philippe_mori hotmail.com> writes:
 I'd really like a parameter decorator that caused either automatic
 conversion of a character (char or wchar) array to a zero-terminated
string,
 a la toStringz, or, preferably, requires a cast (thus causing the
programmer
 to be mindful of the need to null-terminate).

 In fact, I'd quite like any function taking char/wchar* requires an
explicit
 cast from char/wchar[]. Is there a reason why this is not required now?
I would prefer a member function c_str() as in C++ STL. No ugly cast, no unwanted conversions...
Sep 17 2003
next sibling parent "Matthew Wilson" <matthew stlsoft.org> writes:
Does that make a zero-terminated copy, or modify the array itself?

Either way I don't really like it, since it is limiting. There are cases
when the programmer will know that the array is already zero-terminated, so
calling a modifying (or copying and modifying) function will be inefficient.
There will also be cases where the programmer will know that a
zero-termination is not required, and to do one would be inefficient.

I want a cast, and the uglier the better. This will be used in connecting to
legacy C functions, and in that case I think it's a good thing that it's
highly visible (and ugly, if you will).


"Philippe Mori" <philippe_mori hotmail.com> wrote in message
news:bk9oeq$2565$1 digitaldaemon.com...
 I'd really like a parameter decorator that caused either automatic
 conversion of a character (char or wchar) array to a zero-terminated
string,
 a la toStringz, or, preferably, requires a cast (thus causing the
programmer
 to be mindful of the need to null-terminate).

 In fact, I'd quite like any function taking char/wchar* requires an
explicit
 cast from char/wchar[]. Is there a reason why this is not required now?
I would prefer a member function c_str() as in C++ STL. No ugly cast, no unwanted conversions...
Sep 17 2003
prev sibling parent J Anderson <anderson badmama.com.au.REMOVE> writes:
Philippe Mori wrote:

I'd really like a parameter decorator that caused either automatic
conversion of a character (char or wchar) array to a zero-terminated
    
string,
a la toStringz, or, preferably, requires a cast (thus causing the
    
programmer
to be mindful of the need to null-terminate).

In fact, I'd quite like any function taking char/wchar* requires an
    
explicit
cast from char/wchar[]. Is there a reason why this is not required now?



    
I would prefer a member function c_str() as in C++ STL. No ugly cast, no unwanted conversions...
And then you could have d_str() to convert back (just kidding).
Sep 17 2003