Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] Embedded C programme

Status
Not open for further replies.

Sam Cristtina

Junior Member level 1
Joined
May 13, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,380
Hi,
I'm trying to embedded two array. I have constant unsigned int array with 50 elements named array1[50] = {1,2,3...49,50}; and In second constant unsigned int array with 50 elements named array2[50] = {51,52,53...100};
Now I want to embedded this second array2 to array1. so i have changed size of array1 to 100.
How can i add remaining 50 elements of array2 to array1?
is it redefined possible for constant array?
 

Which are you using? If array is defined as constant then the contents and size of the array cannot be changed. The array has to be in RAM to modify it. If it is const type then it will be in ROM.

If you want to add 2nd array to 1st array then 2nd array can be const if values doesn't change and 1st array has to be in RAM with 100 elements. set copy start index to 50 and copy end index to 99.

Loop from copy start index to copy stop index and use


Code C - [expand]
1
2
for(copy_start_idx; copy_start_idx = copy_stop_idx; copy_start_idx++)
array1[copy_start_idx] = array2[copy_start_idx];



https://www.mikroe.com/forum/viewtopic.php?f=13&t=23669&p=119155&hilit=CopyConst2Ram#p119155
 
Last edited:

Which are you using? If array is defined as constant then the contents and size of the array cannot be changed. The array has to be in RAM to modify it. If it is const type then it will be in ROM.

If you want to add 2nd array to 1st array then 2nd array can be const if values doesn't change and 1st array has to be in RAM with 100 elements. set copy start index to 50 and copy end index to 99.

Loop from copy start index to copy stop index and use


Code C - [expand]
1
2
for(copy_start_idx; copy_start_idx = copy_stop_idx; copy_start_idx++)
array1[copy_start_idx] = array2[copy_start_idx];



https://www.mikroe.com/forum/viewtopic.php?f=13&t=23669&p=119155&hilit=CopyConst2Ram#p119155

I know this but is it possible which i have writen next by using preprocessor instruction?
constant unsigned int array1[5] = {1,2,3,4};
constant unsigned int array2[5] = {5,6,7,8};
constant unsigned int array3[10] = array1 + array2 // array3[10] = {1,2,3,4,5,6,7,8}
 

I know this but is it possible which i have writen next by using preprocessor instruction?
constant unsigned int array1[5] = {1,2,3,4};
constant unsigned int array2[5] = {5,6,7,8};
constant unsigned int array3[10] = array1 + array2 // array3[10] = {1,2,3,4,5,6,7,8}

i don't think array3[10] is right for above method bro ?? because addition is add the content of array and put into the array3[]..
 

Explain what you are trying to do. It looks like you are trying to extend the contents of the array by filling it in with the contents of another array, that isn't adding which implies arithmetic operations, it's concatenaton.

You might be able to overlay the second array after the first by creating a union the size of the resulting array and encasing the two smaller arrays within it. I would guess that simply copying the contents from the second array into additional places in the result array would be just as quick and result in less instructions.

Alternatively, and I've never tried this, if all the array entries are the same size (char, int...) you might be able to use something like this:

*array3 = *array1;
*array3[5] = *array2;

working on the principle that single dimensioned arrays are just linear lists. I'm not at all confident that using pointers that way will work though.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top