www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/12/10/13:57:30

Date: Thu, 10 Dec 92 18:27:38 GMT
From: kerr%cass DOT span AT Sdsc DOT Edu
Subject: sys/time.h and time.h
To: djgpp AT sun DOT soe DOT clarkson DOT edu

Greetings from a new djgpp user.

I just noticed something very unusual about sys/time.h.  To put this in
context, I was running some benchmark programs and was dissatisfied with the
1-second resolution given by time().  I decided to use gettimeofday(), which is
accurate to about 0.05 seconds in djgpp. 

gettimeofday() takes two arguments: pointers to structures timeval and timezone
respectively, both defined in sys/time.h.  Now, when you include sys/time.h,
timeval gets defined but _not_ timezone !  Closer examination of sys/time.h and
time.h reveals the cause: sys/time.h includes its parental namesake, and the
latter defines the symbolic name _TIME_H_, thereby causing the definition of
timezone to be skipped in sys/time.h.  Apparently all of this is to avoid
a name conflict with something in time.h that is also named timezone.

This seems hyperstrange to me.  Why does this name conflict exist, and
why is it resolved at the expense of the structure in sys/time.h?
Any explanations would be most welcome.

(BTW, I got around the problem by hand-coding a dummy timezone structure.
In fact, I didn't even need the time zone information.)

Stephen S. Kerr
skerr AT ucsd DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019