0

Hi

I have installed and tried to compile the following using eclipse and Mingw, and it has no problems doing so.

enum ports {  port_0, port_1, Port_2 };

static const struct port_reg_addr_map {

uint8_t *pdr;

uint8_t *podr;

} port_map[]={

[port_0]={reinterpret_cast<uint8_t *>(0x0008C000),  reinterpret_cast<uint8_t *>(0x0008C020)},

[port_1]={reinterpret_cast<uint8_t *>(0x0008C001), reinterpret_cast<uint8_t *>(0x0008C021)},

[port_2]={reinterpret_cast<uint8_t *>(0x0008C002), reinterpret_cast<uint8_t *>(0x0008C022)}};

 

It compiles and the debugger shows the array containing the expected addresses.

When I do the same using E2 and 4.8.4.201604 GCC, I get errors and cannot find a way to compile it.

Do I need to enable some features of the compiler to get it compiled?

The message I get is:

“too many initializers for ….”

 

Regards

Michael

Grigore Dobra answered
    • Hi
      When I in my Mingw setup add a class and define my struct inside this class, it reports the exact same error.
      Is it normal that a struct that compiles normally, create an error when defined in a class?

    • Hi
      I found the mistake in my code….
      searching for “initializing static member c++” reveals that the code put in a class is interpreted as c++ and not to be initialized in the header. If not put in a class the compiler most likely see it as C code and not C++.
      I will split the code into definition in the header class, and initialize the array in the cpp file.
      This should give me a class member “port_reg_addr_map” and work as expected.