|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Pointer to const array? |
Posted: Mon Apr 21, 2008 4:41 am |
|
|
Hi
What is wrong here. The code is just an ex. from a bigger context.
Is I handling the pointer corect?
The problm is I cant accecc the const array?
Code: | //located in prom
const int8 c_data[6]={0xFF,0x41,0x61,0x11,0x91,0xd1};
//test function
void t2(void){
int8* data;
int16 i;
data=&c_data;
for(i=0;i<6;i++) write_data(*data++);
} |
But if I use this function - no problem!
Code: | void t3{
int16 i;
for(i=0;i<6;i++) write_data(c_data[i]);
} |
|
|
|
Matro Guest
|
|
Posted: Mon Apr 21, 2008 5:02 am |
|
|
Below an excerpt of CCS help about constant data tables :
Quote: |
BYTE CONST TABLE [10]= {9,8,7,6,5,4,3,2,1,0};
and to access the table use:
x = TABLE [i];
OR
x = TABLE [5];
BUT NOT
ptr = &TABLE [i];
In this case, a pointer to the table cannot be constructed.
|
I think all is here...
Matro |
|
|
Guest
|
|
Posted: Mon Apr 21, 2008 5:13 am |
|
|
Hi
Yes I have looked at this ex. but, is it impossible???
/F |
|
|
Ttelmah Guest
|
|
Posted: Mon Apr 21, 2008 5:22 am |
|
|
Actually, you can now (only working in the last few compiler versions), have pointers to constant arrays, _but_ you have to use the 'ROM' construct, rather than the 'const' construct. The difference is that the latter includes a header 'program', to access the data. The former just places the data, and has a slightly more complex access arrangement. This allows the code to be able to calculate 'where' the actual data is, and pointers to be used.
So:
Code: |
//located in prom
int8 ROM c_data[6]={0xFF,0x41,0x61,0x11,0x91,0xd1};
//test function
void t2(void){
int8* data;
int16 i;
data=&c_data;
for(i=0;i<6;i++)
write_data(*data++);
}
|
Should work.
The manual has not 'caught up' with this, but it is in the 'readme.txt' that comes with the compiler.
Best Wishes |
|
|
Guest
|
|
Posted: Mon Apr 21, 2008 6:40 am |
|
|
Hi
Thanks, but I cant get it to work using pointers?
I just use the old way... |
|
|
Ttelmah Guest
|
|
Posted: Mon Apr 21, 2008 7:02 am |
|
|
What I posted, compiled, and ran, on 4.070, using putc, instead of write_data, and gave the right output.
Best Wishes |
|
|
Guest
|
|
Posted: Mon Apr 21, 2008 8:00 am |
|
|
Hi.
Thanks for the information:-) |
|
|
|
|
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
|