CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

memcpy problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Chawee
Guest







memcpy problem
PostPosted: Mon Dec 31, 2007 2:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 31, 2007 5:32 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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