|
Boost : |
From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2004-08-25 11:41:54
The implementation of the boost::xtime_get() function in
libs/thread/src/xtime.cpp includes the following code for Windows:
#if defined(BOOST_HAS_FTIME)
FILETIME ft;
...
const boost::uint64_t TIMESPEC_TO_FILETIME_OFFSET =
((boost::uint64_t)27111902UL << 32) +
(boost::uint64_t)3577643008UL;
xtp->sec = (int)((*(__int64*)&ft - TIMESPEC_TO_FILETIME_OFFSET)
/ 10000000);
xtp->nsec = (int)((*(__int64*)&ft - TIMESPEC_TO_FILETIME_OFFSET
- ((__int64)xtp->sec * (__int64)10000000))
* 100);
return clock_type;
#elif ...
(This is reformatted slightly so that Outlook doesn't screw it up.)
The pointer casts are not safe because although the representations
of FILETIME and __int64 are compatible, FILETIME is only 32-bit-
aligned whereas __int64 must be 64-bit-aligned on IA64 (in some
processor modes).
One can instead use union { FILETIME ft; __int64 i64; } and read out
i64, though I'm not sure this code should be unconditionally using
__int64 anyway. There is a longer explanation at
<http://weblogs.asp.net/oldnewthing/archive/2004/08/25/220195.aspx>.
Ben.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk