D
dude.jimbo
I want to copy an array of structs (fixed size array and struct). What I "have" now (yes, this is indeed a non-compilable extract, and yes, "BOOL" is a big no-no, and no, I obviously don't have two globals that should contain the exact same thing):
struct arrayStruct
{
int a;
int b;
BOOL c;
}
struct arrayStruct dest[ARR_SIZE];
struct arrayStruct source[ARR_SIZE];
void SomeCode(void)
{
/* ... */
for (i=0; i<ARR_SIZE; i++)
{
dest.a = source.a;
dest.b = source.b;
dest.c = source.c;
}
}
This can't be right.
Well, that is to say, technically, it ~is~ right, but surely it can be faster
(not to mention that the real example has plenty more members in the struct).
You'd think I could do something along the lines of:
for (i=0; i<ARR_SIZE; i++)
{
dest = source;
}
Or, even better:
dest = source;
OK, OK, *you* don't think you could do that. But *I* think I should be able to
do something ~like~ that. So I tried, and obviously, it failed.
No, in reality, ~I~ failed. But my fragile ego doesn't like to see it spelled
out like that.
("*dest = *source" sort of worked, but only for the first entry in the arrays)
Can someone help me out with *working* syntax? And yes, I should hang my head in
shame. Apart from the fact that I don't normally program in C. In fact, I don't
normally program at all. Oh the joys of looking smart whilst seated in front of
a PC...
Jimbo
struct arrayStruct
{
int a;
int b;
BOOL c;
}
struct arrayStruct dest[ARR_SIZE];
struct arrayStruct source[ARR_SIZE];
void SomeCode(void)
{
/* ... */
for (i=0; i<ARR_SIZE; i++)
{
dest.a = source.a;
dest.b = source.b;
dest.c = source.c;
}
}
This can't be right.
Well, that is to say, technically, it ~is~ right, but surely it can be faster
(not to mention that the real example has plenty more members in the struct).
You'd think I could do something along the lines of:
for (i=0; i<ARR_SIZE; i++)
{
dest = source;
}
Or, even better:
dest = source;
OK, OK, *you* don't think you could do that. But *I* think I should be able to
do something ~like~ that. So I tried, and obviously, it failed.
No, in reality, ~I~ failed. But my fragile ego doesn't like to see it spelled
out like that.
("*dest = *source" sort of worked, but only for the first entry in the arrays)
Can someone help me out with *working* syntax? And yes, I should hang my head in
shame. Apart from the fact that I don't normally program in C. In fact, I don't
normally program at all. Oh the joys of looking smart whilst seated in front of
a PC...
Jimbo