There is no way to automatically allocate static constant's differently than non statics, except place a #pragma CONST_SEG in between them.
When I understand the desired setup correctly, then the idea is to place static constant's into the same bank where all the code of the same compilation unit resides.
While that may be often working, note that it is not safe in general. Some functions could return a pointer to the the static constant across page boundaries, so I would think its a pretty dangerous setup, especially when you cannot review the source code. Also this means that I'm not sure the compiler should be extended to support this.
When looking into ways of archiving this non the less, the main problem I run across is the limitation that ANSI-C does not support to declare static varibles ("extern static int ddd;" is an error).
I tried shortly, but all the solutions I could come up with are to ugly (call them hack) to show
.
- Anyhow I would recommend to try to optimise the non banked constants by some other means.
Maybe the linker option "-cocc" may help to address the constant usage a bit.
- Seldom used constants in your own code could also be allocated into paged memory using far access eventually.
- Externally visible constants (which can be declared!) could be reallocated with something like
// incl.h:#pragma push#pragma CONST_SEG __FAR_SEG MY_CONSTSextern const int sampleConstant @ "MY_CONSTS";#pragma pop
// file.c:#include "incl.h" // ev. via -AddIncl....extern const int sampleConstant = 2;
(technically this also works for static constants, but the compiler issues correctly a warninig for redefining an external as static, that's one of the not so nice hacks I thought of. I'm not recommending hacks
. )
Hmm. Actually static arrays can be declared.
#pragma push#pragma CONST_SEG MY_CONSTSstatic const int array_sample[] @ "MY_CONSTS";#pragma popextern const int array_sample[2] = {2};
Not sure what I should think about this solution at least for arrays. Well anyhow.
Daniel