Structs by ref in D2
bearophile
bearophileHUGS at lycos.com
Thu Aug 20 15:15:07 PDT 2009
This post is about D2 compiler/language.
Is the following code supposed to be wrong in D2? (and if so, then why?)
import std.c.stdio: printf;
struct S { int x, y; }
S produce() {
S s = S(10, 20);
return s;
}
void show(ref S s) {
printf("%d %d\n", s.x, s.y);
}
void main() {
show(produce());
}
That code works in D1.042, while DMD V.2.031 gives the errors:
test.d(10): Error: function temp.show (ref S s) does not match parameter types (S)
test.d(10): Error: produce() is not an lvalue
After a gentle suggestion by Kirk McDonald I have also tried the following signatures, with similar error messages:
void show(ref const(S) s) {
void show(const ref S s) {
passing locally-defined structs by ref is handy (the LDC compiler is currently able to do it, as older D1 compilers too).
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list