string is rarely useful as a function argument

Peter Alexander peter.alexander.au at gmail.com
Wed Dec 28 05:16:20 PST 2011


On 28/12/11 12:42 PM, bearophile wrote:
> Peter Alexander:
>
>> I often get into situations where I've written
>> a function that takes a string, and then I can't call it because all I
>> have is a char[].
>
> I suggest you to show some of such situations.

Any time you want to create a string without allocating memory.

char[N] buffer;
// write into buffer
// try to use buffer as string


>> I think it's telling that most Phobos functions use 'const(char)[]' or
>> 'in char[]' instead of 'string' for their arguments. The ones that use
>> 'string' are usually using it unnecessarily and should be fixed to use
>> const(char)[].
>
> What are the Phobos functions that unnecessarily accept a string?

Good question. I can't see any just now, although I have come across 
some in the past. Perhaps they have already been fixed.





More information about the Digitalmars-d mailing list