[Icc-avr] Const arrays of pointers to const arrays

John Baraclough j_baraclough at zetnet.co.uk
Wed Sep 5 05:01:59 PDT 2007


Hi Bjorn,

This is from the Help file.

const int table[] = { 1, 2, 3 };
const char *ptr1;
char * const ptr2;
const char * const ptr3;

Here table is a table allocated in the program 
memory, ptr1 is an item in the data memory that 
points to data in the program memory, ptr2 is an 
item in the program memory that points to data in 
the data memory, and ptr3 is an item in the 
program memory that points to data in the program 
memory. In most cases, items such as table and 
ptr1 are most typical. The C compiler generates 
the LPM instruction to access the program memory.

Here's how to do it.

const signed char sinus_tab[2][3] =
{
   {1,2,3},
   {4,5,6}
};

const signed char * const pointer[2]  =
{
   sinus_tab[1],
   sinus_tab[0]
};


John


At 08:46 05/09/2007, you wrote:
>Can someone tell me how to define a constant 
>array of pointers to other constant arrays.
>I can do this in assembler but I want the 
>customer to take over the maintenance and therefore
>I wish to have 100% of the code in C.
>
>Here’s a condensed version:
>
>// pointer_test.c
>
>const signed char sinus_tab[2][3] = {
>{1,2,3},{4,5,6}};
>
>/*** Viritual definition (I want something like this)
>const signed char *pointer[2]  = {
>         sinus_tab[1],
>         &sinus_tab[0][0]  };*/
>
>// Working declaration (while the definition is done in assembler)
>extern const unsigned int pointer[2];
>
>// Usage:
>const signed char *get_pointer( unsigned char index )  {
>
>         return (void *)pointer[ index ];
>}
>In assenmler (i.e. wanted result):
>         .area lit(rom, con, rel)
>_pointer::
>         .word _sinus_tab+3
>         .word _sinus_tab
>
>The first constant array (sinus_tab) is ok but the second either
>ends up in ‘idata’ (initiated SRAM) or, I get error message like:
>
>cast from `pointer to const signed char' to 
>`unsigned int' is illegal in constant expressions
>
>Thanx for help
>Björn Lindgren
>
>_________________________________________________________________
>Express yourself instantly with MSN Messenger! 
>Download today it's FREE! 
>http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
>_______________________________________________
>Icc-avr mailing list
>Icc-avr at imagecraft.com
>http://dragonsgate.net/mailman/listinfo/icc-avr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20070905/ab80f5de/attachment.html


More information about the Icc-avr mailing list