BBS水木清华站∶精华区

发信人: althea (边缘人), 信区: Linux        
标  题: Re: time函数怎么调用啊? 
发信站: BBS 水木清华站 (Fri Jan 14 20:55:09 2000) 
 
【 在 linuxrat (叫我老鼠错不了) 的大作中提到: 】 
  gene, I tried time(tt),time(NULL) and time(&ta). All are available! 
  I don't know why you took errors. :( 
  here's my source: 
  ====timetest.c====== 
  #include <stdio.h> 
  #include <time.h> 
  int main() 
  { 
    time_t t, *tt; 
    time_t tr, ta; 
    time_t hello; 
   t=time(tt); 
rat, 你这样的写法不太好吧, tt如果初始就是NULL就没问题(相当于直接传NULL),  
否则会出错的 
当然, 这依赖于编译器, 不一定会报错. 我见过有人写的程序返回局部变量的地址(显然 
不正确), 但运行却没报错 
   tr=time(ta); 
这样写也通过了??? 需要的是 time_t* 
   hello=time(NULL); 
   printf("Time1=%ld\nTime2=%ld\nTime3=%ld\n", t, tr, hello); 
   exit(0); 
  }   
  gcc -o timetest timetest.c 
  ./timetest 
  Result: 
  time=947853049 
  time=947853049 
  time=947853049     
 
 
-- 
※ 修改:·althea 於 Jan 14 21:00:02 修改本文·[FROM:   162.105.39.43] 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 162.105.39.43] 

BBS水木清华站∶精华区