Altera_Forum
Honored Contributor
15 years agothe use of static, get wrong result
Who can tell me why I get the wrong result?
function: alt_u64 tpm_get_ticks(void) { static alt_u64 old_t=0 ; alt_u64 new_t=0; alt_u64 res_t=0; new_t = alt_timestamp(); printf("\n 1 new_t=%x, old_t=%x \n",new_t,old_t); old_t = new_t; printf("\n 2 new_t=%x, old_t=%x \n",new_t,old_t); res_t = (old_t > 0) ? new_t - old_t : 0; printf("\n 3 new_t=%x, old_t=%x \n",new_t,old_t); return res_t; } result: 1 new_t=f5f86c4e, old_t=a 2 new_t=f5f86c4e, old_t=a 3 new_t=f5f86c4e, old_t=a