How do i get GCC to compile my register structure?
How do i get GCC to compile my register structure?
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
Hello Michael,
First of all “Port_2” uses a capital “P”, but it is used with a lowercase “p”.
Then, seeing that you are using C++ constructs in your code, you should either:
1. compile it using rx-elf-g++ instead of rx-elf-gcc
2. rename your file so it uses a “.cpp” extension – this way rx-elf-gcc will call rx-elf-g++ at compile time
You also need a definition for “uint8_t” which is usually found in “stdint.h”.
Hope this helps.
–
Best Regards,
Grigore Dobra,
The GNU Tools Team
Hello Michael,
By following the link below you can find a project we used to test the compilation of the code excerpt you have sent us. It compiles just fine. If still in doubt, we would appreciate you send us your whole project in order to inspect it.
Test project can be found at: https://llvm-gcc-renesas.com/uploads/kuCJ42tXjTQwr94P/rx_struct.7z
Thank you.
–
Best Regards,
Grigore Dobra,
The GNU Tools Team
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.