avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Re: __DATE__ constant, any way to format it differently ?


From: David Brown
Subject: [avr-gcc-list] Re: __DATE__ constant, any way to format it differently ?
Date: Thu, 29 Jan 2009 22:57:53 +0100
User-agent: Thunderbird 2.0.0.19 (Windows/20081209)

Heike C. Zimmerer wrote:
"Anton James Erasmus" <address@hidden> writes:

You can use the following MACROS and functions to get the
values in integer format. You can then display the date and
time in whatever format you desire.

#define COMPILE_HOUR (((__TIME__[0]-'0')*10) +
(__TIME__[1]-'0'))
#define COMPILE_MINUTE (((__TIME__[3]-'0')*10) +
(__TIME__[4]-'0'))
#define COMPILE_SECOND (((__TIME__[6]-'0')*10) +
(__TIME__[7]-'0'))

is __TIME__ guaranteed not to change between invocations?  Else you may
end up at 1:00:00 where 1:59:59 would have been appropriate.


unsigned char GetCompileHour(void)
{
  unsigned char hour=COMPILE_HOUR;
  return(hour);
}
[...]

This all happens in the AVR where space is tight.  I prefer a small
shell script which prepares a .h file containing all constants (date,
build #, hardware revision, etc) in their final representation.

Note that if you declare these functions "static inline", they will avoid the function call overhead and some space - the compiler will reduce them to a single "ldi" instruction. It's still not quite as compact as a compiled string, but it's an improvement.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]