A
anon.asdf
Hi!
OK, lets try "array-copy":
{
char arrayA[3];
arrayA = (char[]){1, 2, 3};
}
it does *not* work since we're trying to make a fixed array-pointer
arrayA, point to another location/address (where there is an
"anonymous" array holding 1, 2 and 3)
hmmm.... but have a look at this:
/*** trickery-candy ****/
#define LEN 3
struct mystruct {
char arr[LEN];
};
{
char arrayA[LEN];
char arrayB[LEN] = {1, 2, 3};
*((struct mystruct *)arrayA) = (struct mystruct){{1, 2, 3}};
*((struct mystruct *)arrayA) = *((struct mystruct *)arrayB);
}
/***************/
->it works! Using no memcpy (from string.h) or any other "normal
method"!!
Would the code for this be very similar to
memcpy(arrayA, arrayB, sizeof(arrayA));
??? (How does it compare?)
(Any other ways of doing this?)
Regards -Albert
OK, lets try "array-copy":
{
char arrayA[3];
arrayA = (char[]){1, 2, 3};
}
it does *not* work since we're trying to make a fixed array-pointer
arrayA, point to another location/address (where there is an
"anonymous" array holding 1, 2 and 3)
hmmm.... but have a look at this:
/*** trickery-candy ****/
#define LEN 3
struct mystruct {
char arr[LEN];
};
{
char arrayA[LEN];
char arrayB[LEN] = {1, 2, 3};
*((struct mystruct *)arrayA) = (struct mystruct){{1, 2, 3}};
*((struct mystruct *)arrayA) = *((struct mystruct *)arrayB);
}
/***************/
->it works! Using no memcpy (from string.h) or any other "normal
method"!!
Would the code for this be very similar to
memcpy(arrayA, arrayB, sizeof(arrayA));
??? (How does it compare?)
(Any other ways of doing this?)
Regards -Albert