I'm trying to avoid the temporary variable. But I cant figure out the correct syntax:
typedef struct {
int n;
int *ptr;
} i_cant_change_this_typedef;
i_cant_change_this_typedef foo;
i_cant_change_this_typedef bar;
int main(void) {
foo.n = 123;
int tmp[] = {0x01,0x02,0x03};
foo.ptr = tmp;
bar.n = 321;
/* can this be done somehow? */
/* bar.ptr = {0x03,0x02,0x01};*/
}
It bugs me to have to make the intermediate tmp variable. The commented line at the bottom should show what I'm trying to do.
Can it be done, and how?
Ah yes, I'm using a regular gcc/g++ here.
UPDATE: I see I should have mentioned that I would prefer a solution that worked equally well in C and C++. It's going to be used in an embedded solution where too complex dynamic allocations should be avoided.