LeoJr2015
Posts: 11
Joined: Sun Mar 01, 2015 4:25 pm

gettimeofday issue

Wed Mar 25, 2015 10:55 pm

I am getting an implicit call warning when I compile my prog related to gettimeofday. I cannot seem to deduce why, as I have included time.h library. Please have a look and see if you see anything out of the usual:

Code: Select all

PI_THREAD (flowrate) {
   
   piHiPri (20) ;
   int lastCount = 0 ;
   struct timeval tv ;
   double nowMillis = 0;
   
   gettimeofday(&tv, NULL);
   
   lastTimeMillis = timevalToMillis(tv.tv_sec, tv.tv_usec);

   if (wiringPiSetup () < 0) {
      fprintf (stderr, "Trouble setting up wiringPi: %s\n", strerror (errno)) ;
      return 1 ;
   }
   if (wiringPiISR (FLOW_METER_PIN, INT_EDGE_FALLING, &incrementPulseCount) < 0) {
      fprintf (stderr, "Trouble setting up ISR: %s\n", strerror (errno)) ;
      return 0 ;
   }
   
   for (;;) {
      printf ("Waiting ... ") ; fflush (stdout) ;
      while (lastCount == flowCounter)
        delay (1000) ;

      gettimeofday(&tv, NULL);
      nowMillis = timevalToMillis(tv.tv_sec, tv.tv_usec);
      printf (" Flow rate: %10lf litres per second\n", calculateFlowRate(flowCounter - lastCount, nowMillis - lastTimeMillis)) ;

      // reset local counter with current count and local time with current time
      gettimeofday(&tv, NULL);
      lastCount = flowCounter ;
      lastTimeMillis = timevalToMillis(tv.tv_sec, tv.tv_usec);
   }  
   return 0 ;
}
The program runs without issue, but I would like to eliminate the warning. Thanks for any help! Let me know if you need other info to help. :shock:

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: gettimeofday issue

Wed Mar 25, 2015 11:01 pm

Have a look at

Code: Select all

man gettimeofday
There should be man pages for all the system calls like gettimeofday Short answer:-

Code: Select all

#include <sys/time.h>

LeoJr2015
Posts: 11
Joined: Sun Mar 01, 2015 4:25 pm

Re: gettimeofday issue

Wed Mar 25, 2015 11:11 pm

AndyD wrote:Have a look at

Code: Select all

man gettimeofday
There should be man pages for all the system calls like gettimeofday Short answer:-

Code: Select all

#include <sys/time.h>
Perhaps thats my fault. Whats the difference between #include <time.h> and #include <sys/time.h> ??

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: gettimeofday issue

Wed Mar 25, 2015 11:20 pm

LeoJr2015 wrote:...Whats the difference between #include <time.h> and #include <sys/time.h> ??
I believe the difference is time.h is ANSI/ISO C and sys/time.h is POSIX.

LeoJr2015
Posts: 11
Joined: Sun Mar 01, 2015 4:25 pm

Re: gettimeofday issue

Wed Mar 25, 2015 11:21 pm

AndyD wrote:
LeoJr2015 wrote:...Whats the difference between #include <time.h> and #include <sys/time.h> ??
I believe the difference is time.h is ANSI/ISO C and sys/time.h is POSIX.
Thank you, sir! :D

Return to “C/C++”