Interfacing to C
Joshua Niehus
jm.niehus at gmail.com
Tue Jun 28 21:15:56 PDT 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110628/ff771212/attachment.html>
More information about the Digitalmars-d-learn
mailing list