This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: How to return 64-bit values in a「mktime」 method

Part Number: MSP432P401R

Tool/software: Code Composer Studio

I am trying to receive seconds since 1900 from the mktime method.

-------------------------------------------------------------------------------------------

#include <stdio.h>
#include <time.h>

int main(void)
{
   time_t timer;
   struct tm t;
   struct tm *t_st;

   t.tm_year = 200;     /* 2100 */
   t.tm_mon  = 4;       /* 5    */
   t.tm_mday = 20;      /* 2   */
   t.tm_wday = 0;       /* sunday */
   t.tm_hour = 14;      /* 14  */
   t.tm_min  = 20;      /* 20   */
   t.tm_sec  = 0;       /* 00   */
   t.tm_isdst= -1;      

   timer = mktime(&t);

   return 0;
}

-------------------------------------------------------------------

However, if you try to receive the elapsed seconds to 2100 as in the above code, Year 2038 problem will occur and you will not be able to receive accurate values.
How to change the return value of mktime from 32bit to 64bit to solve this?

Thank you

  • Please refer to this e2e thread: https://e2e.ti.com/support/tools/ccs/f/81/t/600119

    Hope it can help you.

    Eason

  • Thank you for your reply

    I read the "" thread, but do not know how may be set anywhere because the version is different. My settings screen is shown below.
    On this screen
    Project-> Properties-> GNUCompiler-> Symbols-> Add-> Name = __TI_TIME_USES_64, Val = 1
    I got a compile error.

    By the way, when I debug it, it seems to me that time_t is a 64-bit type and only the return value of mktime is 32 bits.
    Thank you
  • Hi,

    This thread is beyond MSP432. I will re-assign it to another topic.

    Eason

  • user6222186 said:
    How to change the return value of mktime from 32bit to 64bit to solve this?

    The GCC ARM compiler which comes with TI Code Composer Studio (CCS) version 9.3 defines the type of time_t to be a 64-bit signed value.  The version of this compiler is ...

    % arm-none-eabi-gcc --version
    arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
    Copyright (C) 2017 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Do you use a different GCC ARM compiler?

    Thanks and regards,

    -George


  • Thank you for your reply

    When I debugged the code and checked the time_t, it was a 64-bit type.
    I think it is a problem that the return value of mktime is 32 bits, so if you know, please tell me how to change the return value to 64 bits.

    Thank you
  • The function mktime returns a time_t value, which is a signed 64-bit type.

    I suspect you use a different GCC ARM compiler than the one that comes with CCS.  Please check and let me know.

    Thanks and regards,

    -George

  • Thank you for your reply.


    The compiler used is GNU v7.2.1 (Linaro).


    Thanking you in advance

  • Please try an experiment similar to this one.  Create a simple C file ...

    /* file.c */
    #include <time.h>

    Compile this file with a command similar to ...

    % arm-none-eabi-gcc -E file.c > file.pp

    The -E option preprocesses the file.  The redirection puts the result in a new file named file.pp.  Inspect file.pp to see this line ...

    time_t mktime (struct tm *_timeptr);

    Further inspect to see that time_t is a 64-bit signed integer type.

    When you perform this experiment, do you get the same result?  If not, what do you see?

    Thanks and regards,

    -George

  • Thank you for your reply.

    After checking,
    typedef __int_ least64_t __time_t;
    time_t mktime (struct tm * _timeptr);
    Was confirmed.

    By the way, after 0:00 on January 20, 2038, the upper 4 bytes were all 0xFF.

    Thank you.
  • user6222186 said:
    after 0:00 on January 20, 2038, the upper 4 bytes were all 0xFF

    I can reproduce that behavior.  I don't know why.  So, I filed an issue with the team at Linaro that is responsible for the GCC ARM compiler.  Unfortunately, I am unable to make that issue visible to you.  When a response is received, I'll let you know.

    Thanks and regards,

    -George

  • Thank you for your reply.
    We look forward to new replies.

  • The bug you experienced is fixed in GCC ARM compiler versions GNU Arm Embedded Toolchain 8-2018-q4-major or later.  To get this compiler, you have to update to CCS Version 10.  If a more recent version of the compiler does not install by default, you can obtain it from CCS App Center.

    Thanks and regards,

    -George

**Attention** This is a public forum