timeval未返回预期结果

| 我有一些如下所示的代码:
#include <stdio.h>
#include <sys/time.h>

typedef struct{
     struct timeval timestamp;
}teststruct;

class TestClass {
     public:
       TestClass();
       void dosomething(int, int);
};

TestClass::TestClass(){
}

void
TestClass::dosomething(int num, int numb) {
}

int main(void){
     TestClass *testclass = new TestClass();
     teststruct test;
     gettimeofday(&test.timestamp, NULL);
     printf(\"%llu \\n\", test.timestamp.tv_sec);
     testclass->dosomething(1,1);
     printf(\"%llu \\n\", test.timestamp.tv_sec);
}
此代码的输出是: 13825459612132795564 做点什么 5598307500 但我不知道为什么第一个数字搞砸了。同样,为了使数字彼此不同,完全需要类调用。     
已邀请:
我得到
warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 2 has type ‘__time_t’
。应该是一个提示。将编译器的警告级别提高到明智的水平。 当您使用正确的输入类型时,它可以工作。您以其他方式调用UB,读取不是您要读取的内存;像这样的bug会产生有趣的结果,这些结果的行为根据您通常不希望产生变化的因素而有所不同,因为内存的内容会发生变化。     
如果将
%llu
更改为
%lu
,似乎可以使用。 http://codepad.org/YGubabLR     

要回复问题请先登录注册