toStringz or not toStringz

Regan Heath regan at netmail.co.nz
Tue Jul 12 10:04:16 PDT 2011


Gah.. bad grammar.. 1/2 baked sentences..

On Tue, 12 Jul 2011 18:00:41 +0100, Regan Heath <regan at netmail.co.nz>  
wrote:
> On Tue, 12 Jul 2011 17:09:04 +0100, Steven Schveighoffer  
> <schveiguy at yahoo.com> wrote:
>> No, it wouldn't compile.  char[] does not cast implicitly to char *.   
>> (if it does, that needs to change).
>
> Replace foo with foo.ptr, it makes no difference to the point I was  
> making.

Which was that a new D user would pass foo.ptr rather than go looking for,  
and find toStringz.  We've had a number of cases on the learn NG in the  
past.

>> OK, but what if it's like this:
>>
>> char[] foo = new char[100];
>> auto bar = foo;
>>
>> ucase(foo);
>>
>> In most cases, bar is also written to, but in some cases only foo is  
>> written to.
>>
>> Granted, we're getting further out on the hypothetical limb here :)   
>> But my point is, making it require explicit calling of toStringz  
>> instead of implicit makes the code less confusing, because you  
>> understand "oh, toStringz may reallocate, so I can't expect bar to also  
>> get updated" vs. simply calling a function with a buffer.
>
> This is not a 'new' problem introduced the idea, it's a general problem
-->                                     ^by
> for D/arrays/slices and the same happens with an append, right?  In  
> which case it's not a reason against the idea.


More information about the Digitalmars-d mailing list