On Tue, Apr 20, 2010 at 7:37 AM, Kai Tietz <ktiet...@googlemail.com> wrote:
> Hi Patrick,
>
> 2010/4/20 Patrick Galbraith <p...@patg.net>:
>> Hi all,
>>
>> I've stumbled across an issue with gettimeofday() returning an incorrect
>> value with mingw-w64. A simple code sample:
>>
>> #include <stdio.h>
>> #include <sys/time.h>
>>
>> int main (void)
>> {
>>  struct timeval timer;
>>  int retval;
>>  retval= gettimeofday(&timer,NULL);
>>  fprintf(stderr, "retval: %d\n", retval);
>>  fprintf(stderr, "now: %ld\n", time(0));
>>  fprintf(stderr, "now: %ld\n", timer.tv_sec);
>>  return(0);
>>
>> }
>>
>> When compiled using -
>>
>> regular mingw (correct output)
>>
>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff
>> $ gcc -o mtime mtime.c
>>
>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff
>> $ ./mtime.exe
>> retval: 0
>> now: 1271722468
>> now: 1271722468
>>
>> mingw-w64:
>>
>>
>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff
>> $ /c/mingw/bin/x86_64-w64-mingw32-gcc -o mtime mtime.c
>>
>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff
>> $ ./mtime.exe
>> retval: 0
>> now: 1271722480
>> now: 31293027
>>
>> Are there any known issues with gettimeofday() with mingw-w64?
>>
>> Thanks!
>>
>> Patrick
>>
>> ------------------------------------------------------------------------------
>> Download Intel&#174; Parallel Studio Eval
>> Try the new software tools for yourself. Speed compiling, find bugs
>> proactively, and fine-tune applications for parallel performance.
>> See why Intel Parallel Studio got high marks during beta.
>> http://p.sf.net/sfu/intel-sw-dev
>> _______________________________________________
>> Mingw-w64-public mailing list
>> Mingw-w64-public@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>>
>
> what you are seeing here is that time_t type has changed for x64. x64
> doesn't use any longer a 32-bit time_t type. I use 64-bit wide scalar
> instead.
> If you want to have 32-bit time_t the use please the <timefunction>32
> function set and use instead tim32_t type.
>
> Regards,
> Kai

I can't see the use of a time_t type anywhere in the report?
Is there a misunderstanding somewhere?

The problem may be due to strict aliasing violations.
A warning doesn't appear with default CFLAGS, but
after adding -Wstrict-aliasing=2, you get

gettimeofday.c: In function 'getntptimeofday':
gettimeofday.c:42: warning: dereferencing type-punned pointer will
break strict-aliasing rules

The mingw.org version of gettimeofday.c doesn't exhibit
such an issue. Proper use of a union as it the mingw.org
version might be a solution.

--
Ozkan

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to