stdarg x86_64 problems...

John Colvin john.loughran.colvin at gmail.com
Thu Jul 12 02:12:08 PDT 2012


When I compile the following code with -m32 and -m64 i get a 
totally different result, the documentation suggests that they 
should be the same...

import core.stdc.stdarg, std.stdio;

void main() {
	foo(0,5,4,3);
}

void foo(int dummy, ...) {
	va_list ap;
		
	for(int i; i<10; ++i) {
		version(X86_64) {
			va_start(ap, __va_argsave);
		}
		else version(X86) {
			va_start(ap, dummy);
		}	
		else
			static assert(false, "Unsupported platform");
		
		int tmp;
		va_arg!(int)(ap,tmp);
		writeln(ap," ", tmp);
	}
}

when compiled with -m32 I get:

FF960278 5
FF960278 5
FF960278 5
FF960278 5
FF960278 5

and with -m64 I get:

7FFFCDF941D0 5
7FFFCDF941D0 4
7FFFCDF941D0 3
7FFFCDF941D0 38
7FFFCDF941D0 -839302560

(the end stuff is garbage, different every time)

I'm uncertain, even after looking over the stdarg src, why this 
would happen. The correct output is all 5s obviously.


More information about the Digitalmars-d-learn mailing list