SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By SSK
#60519
Dear Forum Members,

I am using CrossStudio for MSP430F1611. My code is having following routine for copying data from one structure to another.

void mem_cpy(void *pp_dest,void *pp_source, unsigned char size)
{
1 #define p_dest ((unsigned char *)pp_dest)
2 #define p_source ((unsigned char *)pp_source)
3
4 while(size)
5 {
6 *p_dest = *p_source;
7 *p_source = p_source++ ;
8 *p_dest = p_dest++ ;
9 size-- ;
10 }
11
12 #undef p_dest
13 #undef p_source
}

The compiler is giving error at line 7 and 8 as lvalue required. Can anyone please clarify the error in code? Is there any limitation for using pointer (void pointer) with CrossStudio?

Thanks in advance.
By n1ist
#60582
You should be incrementing the pointers, not the data you are pointing to...
Code: Select all
while (size--) {
*pdest = *psource;
pdest++;
psource++;
}
[/code]
By SSK
#60959
hello,

I tried the same but it gives error at pdest++ and psource++ statements as lvalue required. If I change the function declaration to unsigned char instead of void, then this works. Is it any way related to compiler settings? if yes, which? As this is standard C syntax, what could be the error? Please clarify the error.

Thanks in advance.