Hi, I have the following C code which gives the compiler error. "error: initializer element is not a constant"
#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')) const unsigned char gCompileHour=COMPILE_HOUR; const unsigned char gCompileMinute=COMPILE_MINUTE; const unsigned char gCompileSecond=COMPILE_SECOND; but the following code compiles without problems and one can see in the assembly generated that the macros do collapse to a single constant. #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')) unsigned char GetCompileHour(void) { unsigned char hour=COMPILE_HOUR; return(hour); } unsigned char GetCompileMinute(void) { unsigned char minute=COMPILE_MINUTE; return(minute); } unsigned char GetCompileSecond(void) { unsigned char second=COMPILE_SECOND; return(second); } Generated assembly using WinAVR 2008-06-10: .file "test.c" __SREG__ = 0x3f __SP_H__ = 0x3e __SP_L__ = 0x3d __CCP__ = 0x34 __tmp_reg__ = 0 __zero_reg__ = 1 .global __do_copy_data .global __do_clear_bss .text .global GetCompileHour .type GetCompileHour, @function GetCompileHour: /* prologue: function */ /* frame size = 0 */ ldi r24,lo8(8) /* epilogue start */ ret .size GetCompileHour, .-GetCompileHour .global GetCompileMinute .type GetCompileMinute, @function GetCompileMinute: /* prologue: function */ /* frame size = 0 */ ldi r24,lo8(40) /* epilogue start */ ret .size GetCompileMinute, .-GetCompileMinute .global GetCompileSecond .type GetCompileSecond, @function GetCompileSecond: /* prologue: function */ /* frame size = 0 */ ldi r24,lo8(43) /* epilogue start */ ret .size GetCompileSecond, .-GetCompileSecond So is the code that gives an error actually incorrect C, or is it a compiler bug ? Regards Anton Erasmus _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list