On Saturday, 7 April 2012 at 22:21:36 UTC, Jonas wrote:
Hello D community! :-)
I was looking for a sane, object-oriented,
possible-to-go-low-level programming language, so I decided to
give D a try today.
good choice, welcome! ;-)
4) What's the difference between `... foo(MyObject obj) { ...
}` and `foo(MyObject* obj)`? What are use cases for explicit
pointers when passing objects? That's not covered in the
documentation AFAIT.
You normally don't need pointers. Objects are always passed by
reference. So MyObject* obj would be redundant.
5) What's wrong with this program? Is it that `printf` doesn't
understand D strings? If so, how do I use D strings in string
formatting?
import std.stdio;
string foo() { return "foobar"; }
int main() {
printf("%s\n", foo());
return 0;
}
printf is a C function which expects 0-terminated strings. D's
strings are variable-length arrays and not zero-terminated.
Don't use printf. Try using writef instead. Same arguments.
Stefan