I'm getting an error compiling the code snippet below:
C:...sketch_timerTest1.ino:32:1: sorry, unimplemented: non-trivial designated initializers not supported
};
^
exit status 1
Compilation error: exit status 1'
struct portBit
{
uint16_t addr;
uint8_t bit;
};
struct mdConst
{
portBit pwmOut;
portBit limCW;
portBit limCCW;
portBit dirOut;
portBit enaOut;
portBit brkInp;
uint16_t timrBase;
};
struct mdVar
{
uint16_t rpm;
uint16_t accel;
float moveLen;
float stepLen;
bool enabled;
bool dirEqCW;
};
mdConst mdConstTbl =
{ // Timer 3
.pwmOut = {PORTE, 4},
.enaOut = {PORTF, 3}
};
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
I believe this kind of structure initialization works with the GNU compiler (assuming I got the {} placements correct) although I haven't actually tried it there (yet) and I don't know what exactly the Arduino compiler doesn't like.
The overall goal here is to use the same subroutines to control 3 identical timers and associated sets of discrete I/O using arrays of structures containing the pertinent constant and variable data.
If you solve the warnings warning: missing initializer for member 'mdConst::someName' [-Wmissing-field-initializers], the error disdappears
C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_839048\sketch_apr16a.ino:32:1: sorry, unimplemented: non-trivial designated initializers not supported
};
^
C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_839048\sketch_apr16a.ino:32:1: warning: missing initializer for member 'mdConst::limCCW' [-Wmissing-field-initializers]
C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_839048\sketch_apr16a.ino:32:1: warning: missing initializer for member 'mdConst::dirOut' [-Wmissing-field-initializers]
C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_839048\sketch_apr16a.ino:32:1: warning: missing initializer for member 'mdConst::enaOut' [-Wmissing-field-initializers]
C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_839048\sketch_apr16a.ino:32:1: warning: missing initializer for member 'mdConst::brkInp' [-Wmissing-field-initializers]
C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_839048\sketch_apr16a.ino:32:1: warning: missing initializer for member 'mdConst::timrBase' [-Wmissing-field-initializers]
exit status 1
Error compiling for board Arduino Mega or Mega 2560.
If you don't see the warnings, set "Compiler warnings" to "ALL" in File → Preferences.
Thanks for the help. I had tried searching for the error text on the forum but not on the whole web thinking this was an IDE issue. I now see that C++ doesn't support what I was trying to do since constructors are supposed to be used for that. For the past 10 years I've been using C rather than C++ for my embedded projects and have become a bit unknowledgeable WRT C++ constructs and aren't familiar enough to be confident I can make that work, especially since I plan to force the table of constants into flash.
Putting the initialization elements in the same order with no gaps does appear to work though so I've got two solutions now.