Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 17, 2003 parameter decorator for zero-terminated strings | ||||
---|---|---|---|---|
| ||||
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? |
September 17, 2003 Re: parameter decorator for zero-terminated strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | > 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... |
September 17, 2003 Re: parameter decorator for zero-terminated strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Mori | 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... > > |
September 18, 2003 Re: parameter decorator for zero-terminated strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Mori | 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).
|
Copyright © 1999-2021 by the D Language Foundation