...get the build date and time from within my program?

Comments

5 comments

  • Avatar
    Martin Honig

    Hello Jon,

    I have a trouble to use your example in version 3.1.1. I have tried

    const uint64_t build_date_number = 0x$(DateYear)$(DateMonth)$(DateDay);

    but I am getting:

    "invalid suffix "x$" on integer constant"

    Do I have to include any specific include to note preprocessor how to use $(DateYear) etc.?

     

    0
    Comment actions Permalink
  • Avatar
    Dr Danish Ali

    If you try to put the individual fields e.g. $(TimeHour) into a decimal number then you can fail because these macros include leading zeroes where appropriate, and C interprets them as meaning an octal value. The compiler does not like:

    int build_hour = 08;

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    Hi Danish,

    You could do something like adding a leading '1' to indicate a decimal literal and then subtract 100, i.e.

    int build_hour = 108 - 100;

    As both values are literals, the compiler will compute the result and it won't produce any additional code.

    Regards,

    Jon

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    Hi Martin,

    You've missed out a step - you need to use the CrossStudio macros to define a C preprocessor definition. So, for example, you might add the following to your Preprocessor Definitions project property:

    BUILD_DATE_NUMBER=0x$(DateYear)$(DateMonth)$(DateDay)

    Once you have done that, you can use the preprocessor definition from within your program as you would any other, for example:

    const unsigned long build_date_number = BUILD_DATE_NUMBER;

    You cannot use the CrossStudio macro directly in your C code, the compiler doesn't know anything about them.

    Regards,

    Jon

    0
    Comment actions Permalink
  • Avatar
    Nico Butler

    It also works like this in case you'd like to have the build date and time as a string:

    BLD_DATE_TIME="$(DateDay)$(DateMonth)$(DateYear) $(TimeHour)$(TimeMinute)"

    (used as Preprocessor Definition)

    Thanks for the heads-up Jon

    0
    Comment actions Permalink

Please sign in to leave a comment.