I believe that what I am trying to do is probably fair, because it is separated in both instances of a comma (not a typical task), but I have no idea and the search does not cause anything about these two specific situations.
In both cases, I used the variable as an index for two parallel arrays.
int a[3] = {10, 20, 30};
int b[3] = {20, 40, 60};
Case # 1: Structure Initialization for Arrays
struct testStruct {
int t1;
int t2;
};
int i = 0;
testStruct test = {a[++i], b[i]}
The expected result of the final line: test = {20, 40}
Situation # 2: Passing specific values from arrays as args functions
void testFunc(int t1, int t2) {
}
int i = 0;
test(a[++i], b[i]);
The expected result of the final line: test(20, 40)
Is this valid code? And if so, is this true in all compilers?
Is the result what I expect? If so, is it because of arrays or because of a comma?
Thank!