| ||||||||
Technical Support Support Resources Product Information | C51: FORMAT OF __DATE__ MACRO HAS CHANGEDInformation in this article applies to:
QUESTIONI 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? ANSWERThe 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
Last Reviewed: Monday, June 26, 2006 | |||||||
| ||||||||