After I found this very helpful Q/A: How to initialize all members of an array to the same value?, I came to wonder, if there is an equivalent for my constant problem of how to exchange data between arrays in C.
These are some of the cases which interests me the most:
- same type to same type, with same size (e.g char to char)
- one type to another, with same size (e.g. const char to unit8)
- smaller one into a bigger one (e.g test[7] to test[70])
My methods for those above would be like this - e.g.:
- array1 = array2
- memcpy(&array2,array1,sizeof(array1))
- eighter memcpytoo, or a for loop through the elements
I hope someone here can provide, or knows where to find, a fine distilled example-collection of different array exchange routines. It's not, that I cannot make it work my self, it's just, that there is this constant insecurity, if the solution is solid.
Oh, and I really hate those for-loops, assign each element individually. For me, the only reason to use them is when there is some additional handling necessary before the exhange is performed - e.g. incrementing the transferred value first, or something like that.
In case this does not sit well with Q/A-Style, I would be happy, if someone could confirm or improve my attempt for example no.2:
#define SIZEOF_ARRAY = 16;
uint8 array2[SIZEOF_ARRAY+1];
const char array1[SIZEOF_ARRAY+1] = {"test"};
memcpy(&array2,array1,sizeof(array1))
 
     
    