Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.