Skip to main content
2 of 2
replaced http://stackoverflow.com/ with https://stackoverflow.com/

This stackoverflow question Declare a specific address for a string in MPLAB XC8 Microchip complier contains an answer:

Rather than tell the linker, for example -L-pappnfo=0x78E0

There is syntax to directly specify the location of a variable, for example:

const unsigned char _app_nfo[31] @ 0x78E0 = {"V0.0 No        - 05/12/12"};

However, this doesn't sound like what you want to do. You say:

I'd rather not specify the address of every constant directly in the source code because the complete project has a lot of them and they can all change size and contents from one version to the next.

Section "3.4.3.3 HOW DO I PLACE VARIABLES IN PROGRAM MEMORY?" of the MPLAB® XC8 C Compiler User’s Guide says:

The const qualifier implies that the qualified variable is read only. As a consequence of this, any variables (except for auto variables or function parameters) qualified const are placed in program memory, thus freeing valuable data RAM

So it looks like all const variables are put in program space automatically, which I think is what you want.

gbulmer
  • 10.1k
  • 21
  • 29