The more interesting question
Steven Schveighoffer
schveiguy at yahoo.com
Wed May 16 14:09:45 PDT 2012
On Wed, 16 May 2012 17:06:41 -0400, Alex Rønne Petersen <alex at lycus.org>
wrote:
> On 16-05-2012 22:42, Steven Schveighoffer wrote:
>> On Wed, 16 May 2012 16:19:36 -0400, Alex Rønne Petersen <alex at lycus.org>
>> wrote:
>>
>>> Theoretically, yes, practically, not really.
>>>
>>> void myLog(string msg)
>>> {
>>> printf(msg);
>>> }
>>
>> Wait, this should be an error. You need toStringz there.
>>
>> -Steve
>
> Sorry, I meant:
>
> void myLog(string msg)
> {
> printf(msg.ptr);
> }
>
> (Which works as expected because string literals are null-terminated.
> This is also how things work when you pass a string literal to a
> const(char)* value; it just does "literal".ptr.)
No, it doesn't:
myLog("abc"[0..1]); // prints abc instead of the requested a
string is not necessarily a literal. A literal has a special polysemous
type, and special properties. An ordinary string does not.
-Steve
More information about the Digitalmars-d
mailing list