Keil Logo

C51: FORMAT OF __DATE__ MACRO HAS CHANGED


Information in this article applies to:

  • C51 Version 5.50

QUESTION

I have just upgraded to version 5.50 of the C51 compiler and I notice that the format of the __DATE__ macro has changed. It used to be something like:

11/08/00

and now it is:

Nov 08 2000

However my code was dependent on the old format. Is there any way to change it back?

ANSWER

The format was changed to meet the ANSI C Standard (see section 6.8.8). There is no option to change the format back, however, some simple C code will allow you to extract the month, day and year from the new format.

The function getdate(), shown below, uses the global array months to place the month, day and year into the global unsigned chars. This can be used as a basis for your own code.

#include <string.h>
#include <stdlib.h>

unsigned char month, day, year;

code const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
                            "Sep", "Oct", "Nov", "Dec"};

void getdate(void)
{
  char temp [] = __DATE__;
  unsigned char i;

  year = atoi(temp + 9);
  *(temp + 6) = 0;
  day = atoi(temp + 4);
  *(temp + 3) = 0;
  for (i = 0; i < 12; i++)
  {
    if (!strcmp(temp, months[i]))
    {
      month = i + 1;
      return;
    }
  }
}

void main(void)
{
  getdate();
  while(1);
}

MORE INFORMATION

  • Refer to the ANSI C Standard, section 6.8.8 Predefined macro names.

  • Refer to Predefined Macros in the Cx51 User's Guide.

SEE ALSO

Last Reviewed: Wednesday, February 28, 2018


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.