> I don`t see that this patch is valid.  I would request here more
> details about reasoning. I would be curious to learn that we have
> useless code in repro for years
>
> Kai

Current code works with msvcrt.dll in Win32 + _USE_32BIT_TIME_T (which is defined by default in Win32).

It doesn't work with msvcr120.dll (or msvcr110.dll) in Win32 + _USE_32BIT_TIME_T, doesn't work with msvcrt.dll in Win32 + 64BIT_TIME_T (which you can achieve by define __MINGW_USE_VC2005_COMPAT). It is also not 100% compliant with current Microsoft documentation.

I think we can choose one from three possibilities:
1) to do nothing (Win32 should die soon),
2) to change header files according M$ documentation and move function aliases from header file to 32-bit libmsvcrt.a (like in patch), it allows to work with msvcr120.dll in Win32 (but still msvcrt.dll in Win32 + 64BIT_TIME_T will be not working), 3) to change header files and 32-bit libmsvcrt.a to 100% compliant with M$ documentation.

At bottom of the page
https://msdn.microsoft.com/en-us/library/w4ddyt9h.aspx
I found information, that M$ made change in time functions in MSVC 2005. It was 10 years ago, now VS 2015 is free for open source projects. We could consider make mingw-w64 100% compliant with M$ documentation.

I attached example code t.cpp (based on page https://msdn.microsoft.com/en-us/library/95e68951.aspx) that works with VS 2015 64-bit & 32-bit & 32-bit + _USE_32BIT_TIME_T.

t.cpp works with GCC 64-bit (msvcrt.dll), GCC 32-bit (msvcrt.dll).

It doesn't work with GCC 64-bit with msvcr120.dll:
$ g++ -Wall -o t-gcc64-msvcr120.exe t.cpp
C:\Users\Mateusz\AppData\Local\Temp\ccmui7l3.o:t.cpp:(.text+0x17): undefined reference to `__imp__ftime'
collect2.exe: error: ld returned 1 exit status

It doesn't work with GCC 32-bit with msvcr120.dll (the same link error).

It can't compile with GCC 32-bit + -D__MINGW_USE_VC2005_COMPAT:
$ g++ -Wall -D__MINGW_USE_VC2005_COMPAT -o tg.exe t.cpp
t.cpp: In function 'int main()':
t.cpp:32:55: error: cannot convert '__time32_t* {aka long int*}' to 'const time_t* {aka const long long int*}' for argument '3'
to 'errno_t ctime_s(char*, size_t, const time_t*)'
     err = ctime_s( timeline, 26, & ( timebuffer.time ) );
                                                        ^

I attached also t0.cpp which works with all variants of VS 2015 and doesn't work with any variant of GCC.

My question is: should I try to make patch for 100% compliance with M$ documentation that works with all variants of GCC?
// crt_ftime64_s.c
// This program uses _ftime64_s to obtain the current
// time and then stores this time in timebuffer.

#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>

int main( void )
{
   struct _timeb timebuffer;
   char timeline[26];
   errno_t err;
   time_t time1;
   unsigned short millitm1;
   short timezone1;
   short dstflag1;

   _ftime( &timebuffer );

    time1 = timebuffer.time;
    millitm1 = timebuffer.millitm;
    timezone1 = timebuffer.timezone;
    dstflag1 = timebuffer.dstflag;

   printf( "Seconds since midnight, January 1, 1970 (UTC): %ld\n", (unsigned 
long)time1);
   printf( "Milliseconds: %d\n", millitm1);
   printf( "Minutes between UTC and local time: %d\n", timezone1);
   printf( "Daylight savings time flag (1 means Daylight time is in "
           "effect): %d\n", dstflag1); 

   err = ctime_s( timeline, 26, & ( timebuffer.time ) );
   if (err)
   {
       printf("Invalid argument to ctime_s. ");
   }
   printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm,
           &timeline[20] );
}

// crt_ftime64_s.c
// This program uses _ftime64_s to obtain the current
// time and then stores this time in timebuffer.

#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>

int main( void )
{
   struct _timeb timebuffer;
   char timeline[26];
   errno_t err;
   time_t time1;
   unsigned short millitm1;
   short timezone1;
   short dstflag1;

   _ftime_s( &timebuffer );

    time1 = timebuffer.time;
    millitm1 = timebuffer.millitm;
    timezone1 = timebuffer.timezone;
    dstflag1 = timebuffer.dstflag;

   printf( "Seconds since midnight, January 1, 1970 (UTC): %ld\n", (unsigned 
long)time1);
   printf( "Milliseconds: %d\n", millitm1);
   printf( "Minutes between UTC and local time: %d\n", timezone1);
   printf( "Daylight savings time flag (1 means Daylight time is in "
           "effect): %d\n", dstflag1); 

   err = ctime_s( timeline, 26, & ( timebuffer.time ) );
   if (err)
   {
       printf("Invalid argument to ctime_s. ");
   }
   printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm,
           &timeline[20] );
}

------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to