ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Including <time.h> instead of <sys/time.h> has fixed the problem. I guess I should have been following my
Kernighan and Ritchie more closely.
Compiling with -O3 and <sys/time.h> gives a non-zero, but incorrect answer of 7000 odd seconds
for an actual delay of 10 seconds! I've no idea what's going on here either. (Compiling with -O3 and
<time.h> works properly.)
So problem solved. Thank you very much for your help.
However, I need to use gettimeofday() from <sys/time.h>. (I need it as it gives access to the microsecond
accuracy timer.) I've included both <time.h> and <sys/time.h>, and the program compiles and runs properly.
However, I was worried that difftime() would be defined twice.
Looking at <sys/time.h> I see it includes <time.h> itself and does not separately define difftime() so
I don't think my including both header files is a problem. (In fact, according to "grep -r difftime *" run in
/usr/include, difftime only occurs in time.h) But that still leaves the puzzle of why difftime does
not work properly when only <sys/time.h> is included.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.