ARM Technical Support Knowledge Articles

FORMAT OF __DATE__ MACRO HAS CHANGED

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

SEE ALSO

Article last edited on: 2006-06-26 15:46:04

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential