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

Pointer to const array?

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








Pointer to const array?
PostPosted: Mon Apr 21, 2008 4:41 am     Reply with quote

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







PostPosted: Mon Apr 21, 2008 5:02 am     Reply with quote

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








PostPosted: Mon Apr 21, 2008 5:13 am     Reply with quote

Hi

Yes I have looked at this ex. but, is it impossible???

/F
Ttelmah
Guest







PostPosted: Mon Apr 21, 2008 5:22 am     Reply with quote

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








PostPosted: Mon Apr 21, 2008 6:40 am     Reply with quote

Hi

Thanks, but I cant get it to work using pointers?

I just use the old way...
Ttelmah
Guest







PostPosted: Mon Apr 21, 2008 7:02 am     Reply with quote

What I posted, compiled, and ran, on 4.070, using putc, instead of write_data, and gave the right output.

Best Wishes
Guest








PostPosted: Mon Apr 21, 2008 8:00 am     Reply with quote

Hi.

Thanks for the information:-)
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