skip to Main Content

I am compliling a C++ file (on a Raspberry Pi5 running Debian 12 with Gnu C++) and the file is auto-generated from a XML datafile. The file just has some const arrays of structs. One of the arrays has an internal array of structs and the compiler is complaining that there are too many initializers. This does not make sense to me, but maybe I have the initializizers wrongly formatted somehow.

The relevant code snippets are:
in the header file:

enum SignalNames
{
        WestEN,
        WestF1,
        WestFM,
        WestYardEnter,
        WestYardEnter2_4,
        EastYeardEntry1_3,
        EastYardEnter2_4,
        EastExit4__Dwarf_,
        NUM_SIGNALS
};
struct SignalConfig {
        static constexpr uint ASPECTCOUNT = 5;
        enum Aspect
        {
                Stop,
                Slow_Aproach,
                Slow_Clear,
                Aproach,
                Clear,
                Hold,
                Go,
                UNUSED
        };
        struct {
                Aspect aspect;
                openlcb::EventId eventid;
        } aspects[ASPECTCOUNT];
};
extern const SignalConfig SignalsCfg[NUM_SIGNALS];

in the C++ file:

const SignalConfig SignalsCfg[NUM_SIGNALS] = {
        {
                {SignalConfig::Stop, 0000000000000000LL},
                {SignalConfig::Slow_Aproach, 0000000000000000LL},
                {SignalConfig::Slow_Clear, 0000000000000000LL},
                {SignalConfig::Aproach, 0000000000000000LL},
                {SignalConfig::Clear, 0000000000000000LL},
        },// WestEN
        {
                {SignalConfig::Stop, 0000000000000000LL},
                {SignalConfig::Aproach, 0000000000000000LL},
                {SignalConfig::Slow_Clear, 0000000000000000LL},
                {SignalConfig::UNUSED, 0LL},
                {SignalConfig::UNUSED, 0LL},
        },// WestF1
        {
                {SignalConfig::Stop, 0000000000000000LL},
                {SignalConfig::Aproach, 0000000000000000LL},
                {SignalConfig::Clear, 0000000000000000LL},
                {SignalConfig::UNUSED, 0LL},
                {SignalConfig::UNUSED, 0LL},
        },// WestFM
        {
                {SignalConfig::Stop, 0000000000000000LL},
                {SignalConfig::Slow_Aproach, 0000000000000000LL},
                {SignalConfig::Slow_Clear, 0000000000000000LL},
                {SignalConfig::Aproach, 0000000000000000LL},
                {SignalConfig::Clear, 0000000000000000LL},
        },// WestYardEnter
        {
                {SignalConfig::Stop, 0000000000000000LL},
                {SignalConfig::Slow_Aproach, 0000000000000000LL},
                {SignalConfig::Slow_Clear, 0000000000000000LL},
                {SignalConfig::Aproach, 0000000000000000LL},
                {SignalConfig::Clear, 0000000000000000LL},
        },// WestYardEnter2-4
        {
                {SignalConfig::Stop, 0000000000000000LL},
                {SignalConfig::Slow_Aproach, 0000000000000000LL},
                {SignalConfig::Slow_Clear, 0000000000000000LL},
                {SignalConfig::Aproach, 0000000000000000LL},
                {SignalConfig::Clear, 0000000000000000LL},
        },// EastYeardEntry1-3
        {
                {SignalConfig::Stop, 0000000000000000LL},
                {SignalConfig::Slow_Aproach, 0000000000000000LL},
                {SignalConfig::Slow_Clear, 0000000000000000LL},
                {SignalConfig::Aproach, 0000000000000000LL},
                {SignalConfig::Clear, 0000000000000000LL},
        },// EastYardEnter2-4
        {
                {SignalConfig::Hold, 0000000000000000LL},
                {SignalConfig::Go, 0000000000000000LL},
                {SignalConfig::UNUSED, 0LL},
                {SignalConfig::UNUSED, 0LL},
                {SignalConfig::UNUSED, 0LL},
        },// EastExit4 (Dwarf)
}; // This is line 145

The error message is:

/home/heller/WendellDepotMusuem/Software/targets/linux.aarch64/WendellDepot.cxx:145:1: error: too many initializers for ‘const WendellDepot::SignalConfig’
  145 | };
      | ^
make[2]: *** [/home/heller/openmrn/etc/prog.mk:288: WendellDepot.o] Error 1

2

Answers


  1. Chosen as BEST ANSWER

    OK, it looks like I just need an additional set of braces around each set of array elements.


  2. You appear to be missing a set of braces when initializing SignalsCfg.

    • You need one set of braces for the SignalsCfg array
    • Within that, you need a set of braces for each SignalCfg
    • Within that, you need a set of braces for the aspects array
    • Within that, you need a set of braces for each of the anonymous struct within the array

    You appear to be missing the last set; you have 3 sets of braces, not 4.

    For example, change each of

            {
                    {SignalConfig::Stop, 0000000000000000LL},
                    {SignalConfig::Slow_Aproach, 0000000000000000LL},
                    {SignalConfig::Slow_Clear, 0000000000000000LL},
                    {SignalConfig::Aproach, 0000000000000000LL},
                    {SignalConfig::Clear, 0000000000000000LL},
            },// EastYardEnter2-4
    

    into

            {{
                    {SignalConfig::Stop, 0000000000000000LL},
                    {SignalConfig::Slow_Aproach, 0000000000000000LL},
                    {SignalConfig::Slow_Clear, 0000000000000000LL},
                    {SignalConfig::Aproach, 0000000000000000LL},
                    {SignalConfig::Clear, 0000000000000000LL},
            }},// EastYardEnter2-4
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search