![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
Passing a const 2D array to a function? |
Posted: Thu Feb 05, 2009 6:08 am |
|
|
Hello,
Is there a trick to pass a const 2D array as parameter to a function.
Code: |
for ex:
const byte img1[6][84] = {0, 1, 2, 3, 4, ...};
const byte img2[6][84] = {8, 6, 3, 3, 4, ...};
etc ...
|
I have several tables and i need to pass a given one to a function.
i have tried:
Code: |
void my_func(byte **img)
{
}
and
void my_func(byte img[6][84])
{
}
|
Thanks... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 05, 2009 7:02 pm |
|
|
I tried for a while and I can't make it work.
You might have to use if-else or switch-case statements to
select which array to access (rather than passing a pointer).
See the TEXT array in glcd.c for an example. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Feb 06, 2009 3:46 am |
|
|
Remember that in CCS, the most efficient way to store a 'const' array, doesn't support pointers.
Simplest solution using this method of storage, is to make the array 'global', and just pass the line number to the function, as an integer. Remember also, that inside the function, you will need to access the array using array accesses (table[a][b]), rather than using pointers, and for operations using pointers, you will need to copy the row to RAM using strcpy, before using these.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|