Re: Portable use of timers



bytebro wrote:
Hi,

I am writing some code which is intended to be built using gcc on 'nix
boxes, (and potentially using DJGPP on Windoze machines). Can someone
suggest what might be useful defines to look for to determine whether
or not a particular system offers the gethrtime() function?

At the moment I've got something like this (not massively generic!):

#if defined(__DJGPP__)
// do stuff to read the Pentium time stamp counter
#elif defined(__sparc) || defined(sparc) || defined(__hppa)
#include <sys/time.h>
// do stuff using gethrtime()
#else
// make do with a lo-res counter/timer
#endif

Any advice appreciated.

This is hard. I've tried to do this sort of thing with include files
before, it's difficult to do and difficult to find out the symbols to
search for. Sometimes there is a feature that no-one has defined a
symbol for, so it is impossible to sense in this way.

It might be a better idea to use a configure script generated by
autoconf or something similar rather than using preprocessor symbols.

If you do search on preprocessor symbols then try to avoid naming
machine architectures on *nix. Don't assume that just because you're
on sparc you will have sys/time.h. Its better to depend on systems so
look for __sun__, __sysv__, __hpux and friends.

.



Relevant Pages

  • Re: Portable use of timers
    ... I am writing some code which is intended to be built using gcc on 'nix ... (and potentially using DJGPP on Windoze machines). ... autoconf or something similar rather than using preprocessor symbols. ... Or you could just make a configure script and toss in few timer tactics ...
    (comp.programming)
  • Re: Portable use of timers
    ... I am writing some code which is intended to be built using gcc on 'nix ... (and potentially using DJGPP on Windoze machines). ... autoconf or something similar rather than using preprocessor symbols. ... Or you could just make a configure script and toss in few timer tactics ...
    (comp.programming)