简体   繁体   中英

trouble with vsnprintf on 64bit windows

I'm using (under windows7, VS2010) a time_t type. So...

If I dump my variable with a simple printf("%d", myvar) Everything is working fine.

But now, If I use a vsnprintf() (or any code using va_start/va_end and co...) with time_t as argument, I get wrong values !?

myprintf(">>%d %d", var1_time, var2_time);

(var1_time and var2_time are both wrong !)

my guess: va_xx functions don't know how to handle 64bit !?

Of course I can use "%lld" but... How can I do act like printf ?

It's just luck that it worked with printf.

time_t is 64 bit (unless you enable the 32 bit version). So using "%d" is wrong. I'm guessing it appears to work as the stack in that case happens to contains zeroes where printf expects to find the upper 4 bytes of your time_t.

Print it as a 64 bit type in both cases.

If you really must treat it as a 32 bit value, you have to cast it, printf("%d", (int)myvar); . But don't do that, dealing with time is cumbersome enough that you don't need to deliberately try to mess it up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM