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

Passing a const 2D array to a function?

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



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

Passing a const 2D array to a function?
PostPosted: Thu Feb 05, 2009 6:08 am     Reply with quote

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...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 05, 2009 7:02 pm     Reply with quote

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.
Ttelmah
Guest







PostPosted: Fri Feb 06, 2009 3:46 am     Reply with quote

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
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