cancel
Showing results for 
Search instead for 
Did you mean: 

Initialized const pointer

papadeltasierra
Associate III

How do I correct this code so that the pointer is a constant and not place into RAM?

```

const typeOfVariable Variable = DEFINED_VARIABLE_VALUE;
const typeOfVariable *pVariable = &Variable;

```

`pVariable` keeps ending up in RAM and I've run out of ideas :-(.

Thanks!

3 REPLIES 3

Not familiar with the STM8 compiler, but static const ?

What is it that your ultimately trying to achieve? Unfortunately the static will limit it to one source file, but also preclude the linker or other sources changing it. The static const is workable to force tables/arrays in to the text rather than data sections in most ARM / x86 tools I've used.

The code pasting tool is via the </> icon in the edit box, the triple quote method doesn't work here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

In this particular case I can live with losing two bytes of RAM but I am interested in case this indicates a more general COSMIC/stm8s "feature" that I need to be aware of.  I copied this code from another processor where this construct works and am puzzled as to why it doesn't with the COSMIC toolset as the pointer really won't every change and everything the linker needs to resolve this is in hand.

AA1
Senior III

COSMIC compiler did what you told him to do. The pointer should be const and not *pointer. Try this:

typeOfVariable * const pVariable = &Variable;