I'm using mspgcc from 20051026 with an MSP430F1611 and compiling with
the -Os flag.

I have noticed that memcpy() sometimes works incorrectly if the source
or destination pointer does not lie on a 2-byte boundary.  If both of
the variables in question are global, the linker complains of a
"warning: internal error: unsupported relocation error", but if one of
the variables is local I get no complaint at all.

So, is memcpy() unsafe to use when dealing with byte arrays?

For example:

#include <stdlib.h>

int main(void) {
        unsigned uint16 = 0;
        unsigned char uint8[3] = {1,2,3};

        // This one works
        memcpy(&uint16, &uint8[0], sizeof(uint16));

        // This one sometimes does not
        memcpy(&uint16, &uint8[1], sizeof(uint16));
}


Regards,
Andrew

Reply via email to