# How to intitalize data in Program Memory

Im using MPLAB IDE & C18 compiler to program Pic18f2550. I have to initialize a const string in program memory to save space in RAM how do I do it ?

-

To put a constant string in data memory you need to use the rom qualifier in C18 compiler:

rom const char[] = "some string";


EDIT: As an advice for future questions you might have regarding the C18 compiler (or any other compiler, for that matter): please read the compiler's manual before asking for help. I haven't used the C18 in a while and I had to look up the information you needed. It only took me 2 minutes to find the manual on the internet and look for the relevant information. I'm talking from experience when I'm saying that it's much more rewarding to find the answers yourself than to ask someone for help, especially when the information is easily available.

-
Yes, that's it - "rom". Got there just before me :-) My answer is incorrect and I'll delete it. – carveone Jul 22 '14 at 10:07
@carveone Yeah, you're answer is only valid for XC8 and HI-TECH PICC compilers – m.Alin Jul 22 '14 at 10:08
Yes, I posted first and then reread the question! – carveone Jul 22 '14 at 10:09
Interesting. Does the compiler not recognize string literals and do this for you? I use AVR, but I vaguely recall something similar (PGM, I think) as a "place this into flash" qualifier. – sherrellbc Jul 22 '14 at 12:17
@KGregory Data memory (SRAM) in microcontrollers is usually much smaller than program memory (Flash). So, if you're running out of data memory, you could put constant variables in program memory to save SRAM space. The downside of variables in program memory is that they take a longer time and more instructions to access. – m.Alin Jul 23 '14 at 13:55