Discussion:
How to manipulate FILETIME structure...
(too old to reply)
a***@gmail.com
2018-03-12 14:54:38 UTC
Permalink
The MSDN documentation specifically states that:

"Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows."

So Matti's 'clean' solution is no good.

Andy
Kaz Kylheku
2018-03-12 16:28:17 UTC
Permalink
Post by a***@gmail.com
"Do not cast a pointer to a FILETIME structure to either a
ULARGE_INTEGER* or __int64* value because it can cause alignment
faults on 64-bit Windows."
So Matti's 'clean' solution is no good.
You replied to a posting from 2002 without proper attribution/quoting.

1. There was no 64 bit windows in 2002. According to the Wikipedia,
the first release of a 64 bit Windows was in 2005:
https://en.wikipedia.org/wiki/X86-64#Windows

2. There are no alignment faults on x86-64; they are disabled by
default. The MSDN wording is probably concerned with the Itanium.
That's a defunct processor that you probably don't have to
worry about.

3. If you have alignment faults, the technique is still possible; just
ensure that the object is aligned to 64 bits. One way it will be
aligned is if it comes from malloc; there are other ways.

Regarding (2), see this StackOverflow:

https://stackoverflow.com/questions/26919269/how-to-enable-alignment-exceptions-for-my-process-on-x64
--
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
m***@gmail.com
2018-03-27 13:50:14 UTC
Permalink
Hi,
SYSTEMTIME st;
FILETIME ft;
GetSystemTime( &st );
SystemTimeToFileTime( &st, &ft );
/* Declare local variable (properly aligned 64 bit variable) */
uint64_t ft_uint64;

assert(sizeof(ft_uint64) == sizeof(ft)); /* static assert is better */

/* Copy content from unaligned FILETIME to aligned ft_uint64 */
memcpy(&ft_uint64, &ft, sizeof(ft_uint64));

/* do whatever you want with 'ft_uint64' value */

if (ft_uint64 == 0x112341243ll)
{
...
}

Regards
--
Maciej Labanowicz
Loading...