Possible minor bug

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Possible minor bug

Eric Tang
Hi avr-gcc mailing list,

I think I have discovered a minor bug. I get the "initializer element is not constant" error when I try to compile the following code with avr-gcc. If I remove the cast, the code compiles without issue. However, its presence does not cause a similar error when I try to compile the code with Clang or with arm-none-eabi-gcc, leading me to believe that there is in fact a bug and that it is specific to avr-gcc.

struct color {
    uint8_t r;
    uint8_t g;
    uint8_t b;
color = (struct color){ 255, 255, 255 };

Thanks,
Eric




_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Possible minor bug

Nigel Winterbottom-2
> struct color {
> uint8_t r;
> uint8_t g;
> uint8_t b;
> } color = (struct color){ 255, 255, 255 };

Compiles fine for me using this version:

nigel@E3510:~$ avr-gcc --version
avr-gcc (AVR_8_bit_GNU_Toolchain_3.5.2_1680) 4.9.2

-- Nigel


_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Possible minor bug

Georg-Johann Lay-2
In reply to this post by Eric Tang
On 02.08.2016 03:09, Eric Tang wrote:

> Hi avr-gcc mailing list,
>
> I think I have discovered a minor bug. I get the "initializer element is
> not constant" error when I try to compile the following code with avr-gcc.
> If I remove the cast, the code compiles without issue. However, its
> presence does not cause a similar error when I try to compile the code with
> Clang or with arm-none-eabi-gcc, leading me to believe that there is in
> fact a bug and that it is specific to avr-gcc.
>
> struct color {
>     uint8_t r;
>     uint8_t g;
>     uint8_t b;
> } color = (struct color){ 255, 255, 255 };
>
> Thanks,
> Eric

Just avoid the compound literal and use a vanilla initializer:

struct color {
     uint8_t r;
     uint8_t g;
     uint8_t b;
} color = { 255, 255, 255 };


cf. also GCC's C language extension re. compound literals

https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html




_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Loading...