www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Interfacing to C

Hello,

I was trying to run the example on the Interfacing to C page (
http://www.d-programming-language.org/interfaceToC.html) and ran into few
issues. To get it to work "as is" i was .dup(ing) strings into new chars
with defined size and passing those with .ptr. Anyway it seemed like quite a
bit of work for something simple so I added const in the signatures and
things worked much more smoothly:

import std.stdio, std.string;

extern (C) int strcmp(const char* string1, const char* string2);

void main()
{
    writeln(myDfunction("foo"));
}

int myDfunction(const char[] s) {
    return strcmp(std.string.toStringz(s), "foo");
}

Was there a reason why the consts were left out?
if this is a typo I'd be happy to update the web page, would be good
experience for a noob like me. (never used GIT before and first time
participating in a community)

Thanks,
Josh
Jun 28 2011