ftime in C++

3 posts / 0 new
Last post
Seventhwonder
Seventhwonder's picture
Offline
Last seen: 3 years 8 months ago
Joined: 2018-12-26 13:50
ftime in C++

Dear all

I am trying to a compile a GLClock app, however I have some difficulty related to ftime()
What should I use ?

The error I am getting is:
$ ppc-amigaos-g++ CGClock.cpp -o CGClock -lGL -lGLU -lGLUT
/tmp/ccTAWsKT.o: In function `_Z14TimerFunction4i':
CGClock.cpp:(.text+0x30f0): undefined reference to `ftime'

Code snippet is:

void TimerFunction4(int value){
struct timeb tb;
time_t tim=time(0);
struct tm* t;
t=localtime(&tim);
ftime(&tb);

//angleSec = (float)(t->tm_sec+ (float)tb.millitm/1000.0f)/30.0f * M_PI;
angleSec = (float)(t->tm_sec)/30.0f * M_PI;
angleMin = (float)(t->tm_min)/30.0f * M_PI + angleSec/60.0f;
angleHour = (float)(t->tm_hour > 12 ? t->tm_hour-12 : t->tm_hour)/6.0f * M_PI+
angleMin/12.0f;

glutPostRedisplay();
glutTimerFunc(1000,TimerFunction4, 1);

void TimerFunction4(int value){
struct timeb tb;
time_t tim=time(0);
struct tm* t;
t=localtime(&tim);
ftime(&tb);

//angleSec = (float)(t->tm_sec+ (float)tb.millitm/1000.0f)/30.0f * M_PI;
angleSec = (float)(t->tm_sec)/30.0f * M_PI;
angleMin = (float)(t->tm_min)/30.0f * M_PI + angleSec/60.0f;
angleHour = (float)(t->tm_hour > 12 ? t->tm_hour-12 : t->tm_hour)/6.0f * M_PI+
angleMin/12.0f;

glutPostRedisplay();
glutTimerFunc(1000,TimerFunction4, 1);
}

salass00
salass00's picture
Offline
Last seen: 7 months 1 week ago
Joined: 2011-02-03 11:27
Re: ftime in C++

The ftime() function is not supported. You can use clock_gettime() (requires newlib.library >= 53.44) or gettimeofday() instead as they provide equivalent functionality.

afxgroup
afxgroup's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 15:26
Re: ftime in C++

You can use this replacement function

  1. struct timeb
  2. {
  3. time_t time;
  4. unsigned short millitm;
  5. short timezone;
  6. short dstflag;
  7. };
  8.  
  9. int
  10. ftime(struct timeb *tb)
  11. {
  12. struct timeval tv;
  13. struct timezone tz;
  14. int retval = -1;
  15.  
  16. if(tb == NULL)
  17. {
  18. goto out;
  19. }
  20.  
  21. if(gettimeofday(&tv,&tz) != 0)
  22. goto out;
  23.  
  24. tb->time = tv.tv_sec;
  25. tb->millitm = tv.tv_usec / 1000;
  26. tb->timezone = tz.tz_minuteswest;
  27. tb->dstflag = tz.tz_dsttime;
  28.  
  29. retval = 0;
  30.  
  31. out:
  32.  
  33. return(retval);
  34. }
Log in or register to post comments