3 variant questions
John C
johnch_atms at hotmail.com
Tue May 12 09:24:03 PDT 2009
Saaa Wrote:
> >
> > import std.stdarg;
> >
> > assert( _arguments[0] is typeid(int*) );
> > auto arg = va_arg!(int*)(_argptr);
> > *arg = 10;
> >
> > Probably.
> >
> > -- Daniel
>
> Calling the following returns an Access Violation Error after
> correctly writing the two lines.
>
> void main()
> {
> int i;
> get( file, `i`, i);
> }
>
> public void get(in char[][] file, in char[] identifier, ...)
> {
> assert( _arguments[0] is typeid(int) );
> writefln(`assert done`);
> auto arg = va_arg!(int*)(_argptr);
> writefln(`assign done`);
> *arg = 7;
> return;
> }
>
>
You get an AV because you're passing the argument by value. You need to pass its address instead.
Try this:
void main() {
int i;
get(file, "i", &i);
writeln(i);
}
It will print "7".
More information about the Digitalmars-d-learn
mailing list