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

2009-01-29 Thread Heike C. Zimmerer
Anton James Erasmus ant...@sentechsa.com 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.




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


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

2009-01-29 Thread David Brown

Heike C. Zimmerer wrote:

Anton James Erasmus ant...@sentechsa.com 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.




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list