James Carlson wrote:
> Don Cragun writes:
>>      void
>>      timeradd(struct timeval *a, struct timeval *b, struct timeval *res);
> [...]
>>      int
>>      timercmp(struct timeval *a, struct timeval *b, CMP);
>>
>>      int
>>      timerisset(struct timeval *tvp);
>>
>>      void
>>      timersub(struct timeval *a, struct timeval *b, struct timeval *res);
> 
> It'd be nice to be able to make 'a', 'b', and 'tvp' const.
> 
> (Man, that "CMP" thing sure is evil ...)
> 
>>      These macros are not available in function form.  All of these macros
>>      evaulate their arguments more than once.  If parameters passed to these
>>      macros are expressions with side effects, the results are undefined.
> 
> Except for timercmp, where the issue is obvious, it's unclear to me
> why the others must be defined as function-like macros, especially as
> ones with hidden side-effect warts.
> 

#define timerclear(t) { struct timeval *a = (t); a->tv_sec = a->tv_usec 
= 0; }

seems to be a reasonable fix.

>>      lint will complain about a constant conditional for timeradd() and
>>      timersub().  Use of the /* LINTED */ comment before timeradd() or
>>      timersub() is recommended.
> 
> Ick.  Is there no way to fix that rather than just documenting it away?
> 

As above:

#define timeradd(i1, i2, o1)                            \
{ struct timeval *a = i1, *b = i2, *result = o1;        \
   result->tv_sec = a->tv_sec + b->tv_sec;               \
   result->tv_usec = a->tv_usec + b->tv_usec;            \
   if (result->tv_usec >= 1000000) {                     \
         ++result->tv_sec;                               \
         result->tv_usec -= 1000000;                      \
   }                                                     \
}

- Bart

-- 
Bart Smaalders                  Solaris Kernel Performance
barts at cyber.eng.sun.com              http://blogs.sun.com/barts
"You will contribute more with mercurial than with thunderbird."

Reply via email to