Given this code:
void FrMemCopy(void *to, const void *from, size_t sz)
{
    size_t sz8 = sz >> 3;
    size_t sz1 = sz - (sz8 << 3);
    while (sz8-- != 0) {
        *((double *)to)++ = *((double *)from)++;
    }
    while (sz1-- != 0) {
        *((char *)to)++ = *((char *)from)++;
    }
}
I am receiving target of assignment not really an lvalue warnings on the 2 lines inside the while loops.
Can anyone break down those lines?
a cast then an increment?
What is a simplier way to write that?
What does the error mean?
It does not like the *((char*)to)++ statement.
Try this:
void FrMemCopy(void *to, const void *from, size_t sz)
{
    size_t sz8 = sz >> 3;
    size_t sz1 = sz - (sz8 << 3);
    double * tod = (double *) to;
    double * fromd = (double *) from;
    while (sz8-- != 0) {
        *(tod++) = *(fromd++);
    }
    char * toc = (char *) tod;
    char * fromc = (char *) fromd;
    while (sz1-- != 0) {
        *(toc++) = *(fromc++);
    }
}
                        You can't apply ++ to the result of a cast, only to an lvalue (a variable).  So you need to create new variable with the appropriate types for the increments:
void FrMemCopy(void *to, const void *from, size_t sz)
{
    size_t sz8 = sz >> 3;
    size_t sz1 = sz - (sz8 << 3);
    double *to1 = (double *)to;
    double *from1 = (double *)from
    while (sz8-- != 0) {
        *to1++ = *from1++;
    }
    char *to2 = (char *)to1;
    char *from2 = (char *)from1;
    while (sz1-- != 0) {
        *to2++ = *from2++;
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With