I’ve googled around and not found an example of what I want to do, except in Java ... but what I want to do is declare an array, then populate it with a dataset later on after it’s declared... like this:
And I should add, please don’t tell me about addressing each element like arry[0] = 21; etc. or tell me about looping and using the integer of the loop ... I’m fully aware of all that ... I need to do it in one line as I described in the OP.
OK, but this creates a NEW variable within the context of the subroutine and does not change the global variable declared at the beginning of the sketch. For example this sketch:
int arry[2];
void showArray() {
Serial.println(String(arry[0]));
Serial.println(String(arry[1]));
}
void setup() {
Serial.begin(9600);
}
void loop() {
int arry[2] = {23, 45};
showArray();
Serial.println(String(arry[0]));
Serial.println(String(arry[1]));
while (1==1){}
}
Not sure why it doesn’t copy all the elements in the array...
HOWEVER, using another function doesn’t really make sense in my case ... if I were going to do that, I would simply define a local array as a temporary storage then copy each element back into the global array. I was trying to avoid doing that for simplicity, but it doesn’t look like it’s possible with base C++.
(that's also probably about as efficient as you can get, even compared to a language that supports group constants natively. In the end, the cpu has the same sort of work to do, and the same instruction set to do it.)