X-Spam-Check-By: sourceware.org Date: Thu, 15 Feb 2007 07:17:33 +0300 From: Andrew Makhorin X-Mailer: The Bat! (v2.0 Beta/1) Personal Reply-To: Andrew Makhorin Message-ID: <13811889795.20070215071733@gnu.org> To: cygwin AT cygwin DOT com CC: Christopher Faylor Subject: Re: strange bug in gettimeofday function MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-detected-kernel: Error: This connection is not (no longer?) in the cache. X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com >>>I detected a strange bug in the standard function gettimeofday. >>>It *sometimes* reports the time which being expressed as the integer >>>number of milliseconds is *less* than the time obtained *earlier* with >>>the same function. >>If you mean that you call gettimeofday twice and you get different >>values at each call, with a difference of about 100 ms, then this is all >>right. Read on... > As the author of the function in question, I would still like to get > a test case. Looks like I do not understand something elementary :( If I compile a test program (see below) with `gcc test.c', it works fine. However, if I compile it with `gcc -O2 test.c', it fails. Could anyone please explain me what is hapenning? #include #include #include double get_time(void) { struct timeval tv; gettimeofday(&tv, NULL); return (double)tv.tv_sec + 1e-6 * (double)tv.tv_usec; } int main(void) { double t0 = get_time(), t1 = get_time(); if (t0 > t1) { int *t; printf("sizeof(double) = %d\n", sizeof(double)); t = (int *)&t0; printf("t0 = %08X %08X\n", t[1], t[0]); t = (int *)&t1; printf("t1 = %08X %08X\n", t[1], t[0]); printf("t1 - t0 = %.20g \n", t1 - t0); exit(EXIT_FAILURE); } return 0; } In case of failure the output is the following: sizeof(double) = 8 t0 = 41D174F7 4F2AE148 t1 = 41D174F7 4F2AE148 t1 - t0 = 0 Thank you, Andrew Makhorin -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/