![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
Constant and Structure |
Posted: Tue Feb 26, 2008 2:16 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Feb 27, 2008 3:27 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Wed Feb 27, 2008 4:22 am |
|
|
Hi Ttelmah,
Thanks for the answer,
I will try the #device const=READ_ONLY.
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|