On 16-05-2012 23:09, Steven Schveighoffer wrote:
On Wed, 16 May 2012 17:06:41 -0400, Alex Rønne Petersen <[email protected]>
wrote:

On 16-05-2012 22:42, Steven Schveighoffer wrote:
On Wed, 16 May 2012 16:19:36 -0400, Alex Rønne Petersen <[email protected]>
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

I was referring to: myLog("abc");

When you start bringing slicing into the mix, you're bound to make C interop harder and more error-prone because of null-termination.

--
Alex Rønne Petersen
[email protected]
http://lycus.org

Reply via email to