I'm trying around wit times. I createt the following (useless) code:
char cChar0[30];
char cChar1[30];
char cChar2[30];
char cChar3[30];
char cChar4[30];
clock_t t1;
clock_t t2;
clock_t t3;
uint16_t t4;
uint32_t t5;
uint16_t i;
uint16_t uInitDone;
void dateTime (void){
if(!uInitDone){
uInitDone = 1;
t1 = clock();
for (i = 0; i < 1000; i++){
sprintf(cChar0,"do something...");
}
t2 = clock();
t3 = t2 - t1;
t4 = (uint16_t)t2 - (uint16_t)t1;
t5 = (uint32_t)t2 - (uint32_t)t1;
sprintf(cChar1, "t1: %u; t2: %u;",t1,t2);
sprintf(cChar2, "t1: %u; t2: %u;",(uint16_t)t1,(uint16_t)t2);
sprintf(cChar3, "t1: %u; t:2 %u;",(uint32_t)t1,(uint32_t)t2);
sprintf(cChar4, "t3: %u; t4: %u; t5: %u;",t3,t4,t5);
}
}
int main(void) {
while(1)
dateTime();
return 0;
}
I was suprised about the result:
cChar0 = "do something..."
cChar1 = "t1: 0;t2: 0;..."
cChar2 = "t1: 0;t2: 10498;..."
cChar3 = "t1: 0;t2: 0;..."
cChar4 = "t3: 1;t4: 10498; t5: 10498;..."
I checked in time.h and found the declaration:
typedef long time_t;
Can anyone explain to me why t2 in cChar1 and cChar3 = 0? Why is t3 in cChar4 = 1 though it seems to be the difference of 0 and 0 (cChar1)? Why is t5 in cChar4 = 10498 though it seems also to be the difference of 0 and 0 (cChar3)?