[Issue 1678] New: ref with varargs generates invalid code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 18 15:20:23 PST 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1678
Summary: ref with varargs generates invalid code
Product: D
Version: 1.023
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: ary at esperanto.org.ar
Given this code:
***
module main;
import std.stdio;
import std.stdarg;
void foo(int x, ...) {
writefln("%d arguments", _arguments.length);
for (int i = 0; i < _arguments.length; i++) {
_arguments[i].print();
int j = va_arg!(int)(_argptr);
writefln("\t%d", j);
}
}
void fooRef(ref int x, ...) {
writefln("%d arguments", _arguments.length);
for (int i = 0; i < _arguments.length; i++) {
_arguments[i].print();
int j = va_arg!(int)(_argptr);
writefln("\t%d", j);
}
}
void main() {
foo(1, 2, 3, 4, 5);
writefln("---");
int x = 1;
fooRef(x, 2, 3, 4, 5);
}
***
the output is:
***
4 arguments
int
2
int
3
int
4
int
5
---
4 arguments
int
1245056
int
4203171
int
1
int
1245004
***
Note that both functions are identical, except the last one has a ref
parameter. Without it, the function works as expected.
--
More information about the Digitalmars-d-bugs
mailing list