[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Compiler bug or Incorrect C ?
From: |
Stu Bell |
Subject: |
RE: [avr-gcc-list] Compiler bug or Incorrect C ? |
Date: |
Thu, 29 Jan 2009 08:27:39 -0700 |
Incorrect C. The difference is in the initializer. In:
> const unsigned char gCompileHour=COMPILE_HOUR;
> const unsigned char gCompileMinute=COMPILE_MINUTE;
> const unsigned char gCompileSecond=COMPILE_SECOND;
You are trying to set a global through the initializer to a variable
value. At *compile time*, what is the value of TIME[0]? Unknown.
Ergo, the compiler error.
In the functions:
> unsigned char GetCompileHour(void)
> {
> unsigned char hour=COMPILE_HOUR;
> return(hour);
> }
COMPILE_HOUR is run-time computable, and so works.
Best regards,
Stu Bell
DataPlay (DPHI, Inc.)
> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden
> On Behalf Of Anton James Erasmus
> Sent: Wednesday, January 28, 2009 11:48 PM
> To: address@hidden
> Subject: [avr-gcc-list] Compiler bug or Incorrect C ?
>
> 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
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>
- [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Ruud Vlaming, 2009/01/26
- RE: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/26
- Re: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Timo Sandmann, 2009/01/26
- RE: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/26
- Re: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Ruud Vlaming, 2009/01/28
- RE: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/28
- [avr-gcc-list] Compiler bug or Incorrect C ?, Anton James Erasmus, 2009/01/29
- RE: [avr-gcc-list] Compiler bug or Incorrect C ?, Weddington, Eric, 2009/01/29
- RE: [avr-gcc-list] Compiler bug or Incorrect C ?,
Stu Bell <=
- Re: [avr-gcc-list] Compiler bug or Incorrect C ?, Joerg Wunsch, 2009/01/29
- Re: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Ruud Vlaming, 2009/01/29
- RE: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/29
- Re: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Steven Michalske, 2009/01/29
- RE: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/29
- Re: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Ruud Vlaming, 2009/01/30
- RE: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/30
- RE: [avr-libc-dev] RE: [avr-gcc-list] noavr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/30
- Re: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Ruud Vlaming, 2009/01/30
- RE: [avr-gcc-list] no avr/lib/avr25/attiny13a/Makefile.in, Weddington, Eric, 2009/01/30