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 support@ccsinfo.com

Constant and Structure

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



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

Constant and Structure
PostPosted: Tue Feb 26, 2008 2:16 pm     Reply with quote

Hello everybody,

I was triyng to use this:
Stack16.h:
Code:
typedef struct
{
   unsigned int* FIFOStart;
   unsigned int* FIFOEnd;
}sctFIFOParams;

void FIFO_Init(sctFIFOParams* FIFOParams);


main.c:
Code:
// FIFO declaration.
#define FIFO_TX_SIZE   2
unsigned char FIFOTxBuff[FIFO_TX_SIZE];
const sctFIFOParams ParamFIFOTx =
{
   FIFOTxBuff,
   (FIFOTxBuff+FIFO_TX_SIZE)
};

FIFO_Init(&ParamFIFOTx);


I've got the "Expecting an identifier" error for "&ParamFIFOTx" on the last line of this code.

If I remove "const" before my structure, I don't have any error.
Is it not possible to declare a constant structure?

Thanks for any response,
Franck.

Compiler: PCD 4.068.
Ttelmah
Guest







PostPosted: Wed Feb 27, 2008 3:27 am     Reply with quote

OK.
Key to understand, is that by default 'const', has a different meaning in CCS, from most compilers. Const in CCS, means 'store this in ROM'. Generally in most compilers, 'const' means 'flag this value as one that cannot change at runtime'. The former meaning makes it very hard to store pointers. You can change the meaning (on recent compilers, by using:
#device const=READ_ONLY
With this, the code should work.
However in the PIC, since there is no hardware memory management, with the second type of 'const' declaration, it is always possible to accidentally access such a value (pointer arithmetic without proper bounds checking), so the declaration in this form, is not that 'useful', except as a reminder to the programmer that the value is meant to be fixed.

Best Wishes
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 4:22 am     Reply with quote

Hi Ttelmah,
Thanks for the answer,
I will try the #device const=READ_ONLY.

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