|
|
View previous topic :: View next topic |
Author |
Message |
Chawee Guest
|
memcpy problem |
Posted: Mon Dec 31, 2007 2:00 am |
|
|
Hi,
i have a problem with memcpy.
Here is my code:
////////////////////////////////////////////////////////////////////////
BYTE CONST data1[30] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32
0x00, 0x00, 0x5F, 0x5F, 0x00, 0x00, // 33
0x00, 0x03, 0x00, 0x03, 0x00, 0x00, // 34
0x14, 0x3E, 0x14, 0x14, 0x3E, 0x14, // 35
0x4E, 0x4A, 0xFF, 0x4A, 0x7A, 0x00, // 36
};
BYTE CONST data2 [5][6] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32
0x00, 0x00, 0x5F, 0x5F, 0x00, 0x00, // 33
0x00, 0x03, 0x00, 0x03, 0x00, 0x00, // 34
0x14, 0x3E, 0x14, 0x14, 0x3E, 0x14, // 35
0x4E, 0x4A, 0xFF, 0x4A, 0x7A, 0x00, // 36
};
void print_array()
{
int i = 0;
int font_data[50];
memcpy(font_data, data1[0], 6);
for(i=0;i<30;i++)
{
printf(" 0x%x",font_data[i]); // IF I USE A "ONE DIMENSION ARRAY"
delay_ms(100); // I GET GARBAGE
}
memcpy(font_data, data2[0], 6);
for(i=0;i<30;i++)
{
printf(" 0x%x",font_data[i]); // IF I USE A "TWO DIMENSION ARRAY"
delay_ms(100); // THE RESULT IS OK
}
}
////////////////////////////////////////////////////////////////////////
Can anyone help me on my problem, because i want to use memcpy also
at "normal arrays"
Compiler Version 4.048
Happy New Year
Chawee |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 31, 2007 5:32 am |
|
|
You need to give it the starting address of the array:
Quote: | memcpy(font_data, data1, 6); |
Because CCS doesn't support pointers to constant data,
you can't do address arithmetic on the source address.
For example, the 2nd parameter can't be 'data+6' or &data[6]
or &data[i]. The compiler gives an error message if you do that.
But CCS makes an exception to their rule, by allowing memcpy to
work if you give it the starting address of the 'const' array, as
shown in the example above. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|