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 CCS Technical Support

memcpy broken?

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



Joined: 12 Oct 2003
Posts: 13

View user's profile Send private message

memcpy broken?
PostPosted: Mon Jun 14, 2004 8:55 am     Reply with quote

Question

Since version 3.142 and also in the recent 3.202 I have experienced problems with the memcpy command:

memcpy(receivedtelegrams[receiver][0], receivedtelegrams[receiver][1],40);

Even the receivedtelegrams array is #located at 0x0600 the memory is
moved from array no 1 to start of the memory array and not to
the memory at 0x0600.

Does anyone have a clou while this is not working (anymore)


Best regards

Poul
Ttelmah
Guest







Re: memcpy broken?
PostPosted: Mon Jun 14, 2004 9:03 am     Reply with quote

kometen wrote:
Question

Since version 3.142 and also in the recent 3.202 I have experienced problems with the memcpy command:

memcpy(receivedtelegrams[receiver][0], receivedtelegrams[receiver][1],40);

Even the receivedtelegrams array is #located at 0x0600 the memory is
moved from array no 1 to start of the memory array and not to
the memory at 0x0600.

Does anyone have a clou while this is not working (anymore)


Best regards

Poul

Your syntax is incorrect. You need an address, not an array element content. Hence:
&receivedtelegrams[receiver][0]

and the same for the target address.
What you post would not work under a 'normal' C, and if it worked in the past, it was because the compiler was fixing the incorrect syntax...
For an array, the 'default' in C, is that the array name (without an index), is the address of the element, but a fully addressed element, returns the contents of the element, so the address.

Best Wishes
kometen



Joined: 12 Oct 2003
Posts: 13

View user's profile Send private message

PostPosted: Mon Jun 14, 2004 12:08 pm     Reply with quote

Question
Thanks for your answer. Before I wrote to the forum I looked into the manual and found the same answer, however if I use:
memcpy(&receivedtelegrams[receiver][0], &receivedtelegrams[receiver][1],40);
it wont compile: Expecting an identifier.

This one compiles without error:
memcpy(receivedtelegrams[&receiver][0], receivedtelegrams[&receiver][1],40);

but will it work? I cannot test it before tomorrow, what do you think?

thanks again

Poul
Ttelmah
Guest







PostPosted: Tue Jun 15, 2004 10:29 am     Reply with quote

kometen wrote:
Question
Thanks for your answer. Before I wrote to the forum I looked into the manual and found the same answer, however if I use:
memcpy(&receivedtelegrams[receiver][0], &receivedtelegrams[receiver][1],40);
it wont compile: Expecting an identifier.

This one compiles without error:
memcpy(receivedtelegrams[&receiver][0], receivedtelegrams[&receiver][1],40);

but will it work? I cannot test it before tomorrow, what do you think?

thanks again

Poul

The syntax _should_ work.
Remember 'receiver' has to be a defined variable at this point, as does 'receivedtelegrams'.
I have just compiled the code as:
int8 receivedtelegrams[50][2];
int8 receiver;
receiver=4;
memcpy(&receivedtelegrams[receiver][0], &receivedtelegrams[receiver][1],40);

and it compiles fine.
Your second syntax should not work (you are handing the address of 'receiver' as an index to the array, and returning the contents of this). However if this compiles, the former should compile too...

Best Wishes
kometen



Joined: 12 Oct 2003
Posts: 13

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 3:00 pm     Reply with quote

[The syntax _should_ work.
Remember 'receiver' has to be a defined variable at this point, as does 'receivedtelegrams'.
I have just compiled the code as:
int8 receivedtelegrams[50][2];
int8 receiver;
receiver=4;
memcpy(&receivedtelegrams[receiver][0], &receivedtelegrams[receiver][1],40);

and it compiles fine.
Your second syntax should not work (you are handing the address of 'receiver' as an index to the array, and returning the contents of this). However if this compiles, the former should compile too...

--------------------------------------------------------

Thanks again.
It is kind of you to help me.

My declaration of the array is:
char receivedtelegrams[8][3][40]; // 8 transmitters with each 3 telegrams of 40 char.

I believe that it is the declaration of the 40 char that stops the compilation.

Based on your suggestion can I use this one then:

memcpy(&receivedtelegrams[receiver][0][0], &receivedtelegrams[receiver][1][0],40);

???

Thanks again

poul
Ttelmah
Guest







PostPosted: Wed Jun 16, 2004 2:10 am     Reply with quote

kometen wrote:
[The syntax _should_ work.
Remember 'receiver' has to be a defined variable at this point, as does 'receivedtelegrams'.
I have just compiled the code as:
int8 receivedtelegrams[50][2];
int8 receiver;
receiver=4;
memcpy(&receivedtelegrams[receiver][0], &receivedtelegrams[receiver][1],40);

and it compiles fine.
Your second syntax should not work (you are handing the address of 'receiver' as an index to the array, and returning the contents of this). However if this compiles, the former should compile too...

--------------------------------------------------------

Thanks again.
It is kind of you to help me.

My declaration of the array is:
char receivedtelegrams[8][3][40]; // 8 transmitters with each 3 telegrams of 40 char.

I believe that it is the declaration of the 40 char that stops the compilation.

Based on your suggestion can I use this one then:

memcpy(&receivedtelegrams[receiver][0][0], &receivedtelegrams[receiver][1][0],40);

???

Thanks again

poul

Er. Of course it is!.
You are declaring a three dimensional array, and then trying to address it with two dimensions....
For a three dimensional array, 'array[x][y]', does _not_ define a unique location, which is needed for the address to be solved.
The syntax you show with all three dimensions should work, _but_ you may have a problem with array size. Generally, in PICs, the largest array is limited to the biggest RAM area in one bank. On the 18F PICs, this is avoided, but you might still run into problems depending on the order in which other variables are declared, and on the compiler version (the fixes here, have had intermittent problems, so I'd treat any array larger than 256 characters as 'possibly dangerous'). It may well work fine, but some people (myself included), have found it necessary to 'push' the compiler a little, and manually use the functions like #locate, to override the 'defaults'.
So it should work (assuming this is a large 18F family chip), but be prepared to possibly have to do a little 'manual' memory management latter...

Best Wishes
kometen



Joined: 12 Oct 2003
Posts: 13

View user's profile Send private message

PostPosted: Thu Jun 17, 2004 1:00 pm     Reply with quote

Very Happy

Dear friend.

Many thanks for your help. I was very confused about this matter since the code has been working fine for at least one year. I believe that one of the reasons for the problem was, next to my coding error, that the new version of the compiler used the optimization level 9, because I was able to avoid some of the errors by reduzing the level to 5.
Anyway, thanks to you, my program is again working fine.

best regards

Poul
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