下面的代码打印为1030432081
(这是错误的)编译时使用gcc -m32 time.c
,而编译时没有-m32
标志时它工作正常。有什么办法可以让这个工作?如何使用uint64_t和-m32?
#include <sys/time.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
void test() {
struct timeval t;
gettimeofday(&t, NULL);
uint64_t microseconds = t.tv_usec + t.tv_sec * 1000000;
printf("%"PRId64, microseconds);
}
int main() {
test();
}
'(uint64_t)1000000' –
解决了这个问题。你能解释为什么吗? (如果你愿意,可以将它作为答案) – ben