Menu

#3979 error 147: excess elements in struct initializer

open
nobody
error 147 (1)
Front-end
2
2026-05-10
2026-04-19
No

SDCC TD- 4.5.0 #15242 (MINGW32)

typedef union {
struct {
uint8_t A;
uint8_t B;
uint8_t C;
uint8_t D;
};
uint32_t LongWord;
} Union_t;

static const Union_t UnionData =
{
.A = 128,
.B = 128,
.C = 128,
.D = 128
};

bug.c:13: error 147: excess elements in struct initializer after 'UnionData'

1 Attachments

Discussion

  • Maurizio Spagni

    Maurizio Spagni - 2026-04-26

    Things are even worse!

    #include <stdint.h>
    
    typedef struct {
      uint8_t n;
      union {
        uint8_t A;
        struct {
          uint8_t B;
          uint8_t C;
        };
        struct {
          uint8_t D;
          uint8_t E;
          uint8_t F;
        };
      };
    } Struct_t;
    
    static const Struct_t Foo1 =
    {
      .n = 100,
      .A = 123
    };
    
    static const Struct_t Foo2 =
    {
      .n = 100,
      .C = 123
    };
    
    static const Struct_t Foo3 =
    {
      .n = 100,
      .E = 123
    };
    
    volatile uint8_t __at(1000) Size;
    
    void main(void)
    {
      Size = sizeof(Struct_t);
      Size = sizeof(Foo1);
      Size = sizeof(Foo2);
      Size = sizeof(Foo3);
    }
    

    Please note that in all cases Size = 4 -> correct
    But look at the listing and you'll see that the constants are all bigger (and wrong).

     
  • Maurizio Spagni

    Maurizio Spagni - 2026-05-10

    Sorry, probably I misplaced the category of this bug.
    Probably it's real place should be "front end".

     
    • Philipp Klaus Krause

      Fixed (not the bug, just the category).

       
  • Philipp Klaus Krause

    • Category: Build --> Front-end
     

Log in to post a comment.

MongoDB Logo MongoDB