strange bug in gettimeofday function

Shankar Unni shankarunni@netscape.net
Mon Feb 19 20:53:00 GMT 2007


Andrew Makhorin wrote:

> {       double t0 = get_time(), t1 = get_time();

[Maybe OT?]

1. I can't remember if C guarantees that comma-separated *declarations* 
are initialized in order or not..  And to think I used to be an ANSI C 
guru :-(.

2. The reason that the "t0 > t1" fails, but t0 and t1 get dumped to be 
the same, is that C allows the implementation to use larger-than-64-bit 
(for 64-bit) intermediate double representations. In the case of X86, 
the CPU's floating-point registers are 80 bits wide.

When they get written to stack, the value is rounded (or truncated?) to 
64 bits.

In the optimized code, I'll bet you that the two locals (t0 and t1) are 
kept entirely in registers, at least until the "&t0" and "&t1" calls. So 
at the point of comparison, it's comparing two 80-bit values, but when 
you flush them to memory to dump them as integer values, they get 
truncated to the (same) 64-bit value.


--
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/



More information about the Cygwin mailing list