Menu

#783 incorrect types in struct timeval

v1.0 (example)
open
nobody
timeval (1)
5
2021-07-10
2019-01-28
No

The struct timeval should contain two members of types time_t and suseconds_t , according to spec:

time_t         tv_sec      seconds
suseconds_t    tv_usec     microseconds

but in header {underscore}timeval.h where is structure defined are both types as long.
This inconsistency is causing warnings in cross-platform code.

Related

Bugs: #783

Discussion

  • Kai Tietz

    Kai Tietz - 2019-01-29

    Hello,

    that here we use long is by intention. The declaration of this timeval
    structure is (was) inconsistent c-runtime vs Windows SDK in context of
    gcc. Therefore we made sure to use underlying base types instead. The
    use of "long" is mainly caused by compatibility with Cygwin. As for
    Cygwin this structure has 64-bit members (instead of 32-bit ones as
    for native Windows).

    To understand your issue, it would be interesting if you could provide
    small testcase, and a description of used compiler, and how it get
    invoked.

    Cheers,
    Kai

    Am Mo., 28. Jan. 2019 um 13:15 Uhr schrieb Lukas Kucera
    kerbos@users.sourceforge.net:


    [bugs:#783] incorrect types in struct timeval

    Status: open
    Group: v1.0 (example)
    Labels: timeval
    Created: Mon Jan 28, 2019 12:15 PM UTC by Lukas Kucera
    Last Updated: Mon Jan 28, 2019 12:15 PM UTC
    Owner: nobody

    The struct timeval should contain two members of types time_t and suseconds_t , according to spec:

    time_t tv_sec seconds
    suseconds_t tv_usec microseconds

    but in header {underscore}timeval.h where is structure defined are both types as long.
    This inconsistency is causing warnings in cross-platform code.


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mingw-w64/bugs/783/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Bugs: #783

    • Lukas Kucera

      Lukas Kucera - 2019-01-29

      Dear developer,

      thank you for the fast response and clarification of the inconsistency.

      It's not a big issue and I can live with this feature, so I won't provide a
      test case.

      Best regards,

      Lukas Kucera

      --

      Lukáš Kučera

      From: Kai Tietz ktietz70@users.sourceforge.net
      Sent: Tuesday, January 29, 2019 10:37 AM
      To: [mingw-w64:bugs] 783@bugs.mingw-w64.p.re.sourceforge.net
      Subject: [mingw-w64:bugs] Re: #783 incorrect types in struct timeval

      Hello,

      that here we use long is by intention. The declaration of this timeval
      structure is (was) inconsistent c-runtime vs Windows SDK in context of
      gcc. Therefore we made sure to use underlying base types instead. The
      use of "long" is mainly caused by compatibility with Cygwin. As for
      Cygwin this structure has 64-bit members (instead of 32-bit ones as
      for native Windows).

      To understand your issue, it would be interesting if you could provide
      small testcase, and a description of used compiler, and how it get
      invoked.

      Cheers,
      Kai

      Am Mo., 28. Jan. 2019 um 13:15 Uhr schrieb Lukas Kucera
      kerbos@users.sourceforge.net kerbos@users.sourceforge.net :


      [bugs:#783] https://sourceforge.net/p/mingw-w64/bugs/783/ incorrect types
      in struct timeval

      Status: open
      Group: v1.0 (example)
      Labels: timeval
      Created: Mon Jan 28, 2019 12:15 PM UTC by Lukas Kucera
      Last Updated: Mon Jan 28, 2019 12:15 PM UTC
      Owner: nobody

      The struct timeval should contain two members of types time_t and
      suseconds_t , according to spec:

      time_t tv_sec seconds
      suseconds_t tv_usec microseconds

      but in header {underscore}timeval.h where is structure defined are both
      types as long.
      This inconsistency is causing warnings in cross-platform code.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/mingw-w64/bugs/783/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/


      [bugs:#783] https://sourceforge.net/p/mingw-w64/bugs/783/ incorrect types
      in struct timeval

      Status: open
      Group: v1.0 (example)
      Labels: timeval
      Created: Mon Jan 28, 2019 12:15 PM UTC by Lukas Kucera
      Last Updated: Mon Jan 28, 2019 12:15 PM UTC
      Owner: nobody

      The struct timeval should contain two members of types time_t and
      suseconds_t , according to spec:

      time_t tv_sec seconds
      suseconds_t tv_usec microseconds

      but in header {underscore}timeval.h where is structure defined are both
      types as long.
      This inconsistency is causing warnings in cross-platform code.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/mingw-w64/bugs/783/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #783

    • Chris Spiegel

      Chris Spiegel - 2021-07-10

      To understand your issue, it would be interesting if you could provide
      small testcase, and a description of used compiler, and how it get
      invoked.

      I can't speak for the reporter, but I ran into this issue with the following code:

      struct timeval tv = { 0 };
      localtime(&tv.tv_sec);
      
      $ x86_64-w64-mingw32-gcc -Wall t.c
      
      t.c: In function main:
      t.c:7:15: warning: passing argument 1 of localtime from incompatible pointer type [-Wincompatible-pointer-types]
          7 |     localtime(&tv.tv_sec);
            |               ^~~~~~~~~~
            |               |
            |               long int *
      In file included from t.c:1:
      /usr/share/mingw-w64/include/time.h:232:62: note: expected const time_t * {aka const long long int *} but argument is of type long int *
        232 | static __inline struct tm *__CRTDECL localtime(const time_t *_Time) { return _localtime64(_Time); }
            |
      

      This is MinGW 8.0.0 with MinGW GCC 10.2.1 (I'm not on Debian, but I used packages from Debian sid, I believe). Since localtime takes a time_t, it's expecting a 64-bit value, but by making tv_sec a long, there's an incompatibility.

       

Log in to post a comment.