I am importing/porting existing C code to C++. I am hoping to make as few changes to the existing body of code as possible to minimize preterbing the existing code. This code makes use of static named initialization of nested structures. For quick made up example:
Car car =
{
.color = RED,
.tire.tread = OLD,
.tire.diameter = 27.106,
.tire.material.type = RUBBER,
.tire.material.density = 700,
};
I figured out that these are called designated initializers.
I learned about GNU initializers but I haven't figured out how to implement hierarchy with it.
I read that designated initializers are supported in g++ with c++11 enabled, but that didn't seem to work for me.
The code I am porting has pages of initialization with at least four layers deep of hierarchy. So I am trying to look for a straightforward transformation which doesn't get too involved.
I am looking for one of these possible solutions:
- How to enable C99 designated initializers
- How to formulate hierarchical GNU style initialization
- What is a C++ equivalent way to do this which wouldn't be error prone transcribing war and peace.
- An obvious solution I haven't thought of
I am using g++ version
g++.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0