Look into the differences between constants and variables.
Look into the differences between constants and variables.
Why pay for overpriced toys when you can have
professional grade tools for FREE!!!
Well, when I didn't define the question correctly I got what I asked for. What I should have asked was, do both constants and variables use up memory or resources when programs compile or execute?
According to what I've read in the PBP3 manual, the answer for constants is they don't use memory of the micro-controller. They make substitutions during compile which I would assume uses less program bits.
Variables do use memory and depending how they are defined they can use a goodly portion. I assume that if a variable is defined as a word and you're only using a few bits you'd be wasting space. Better off defining it as a byte or using a small routine to store those bits as part of a larger word/byte. So if you're trying to save memory for other things, and your variable doesn't need to change, then defining it as a constant would free up RAM to be used elsewhere.
I've yet to write a program where I'm concerned about memory but I figure I'd start with good habits. Especially ones that let me program more efficiently.
Thanks for making me read the manual. It really is a wealth of info.
So, if I understand the question, “Is there a difference between the following code snippets?”
Code:MyByte VAR BYTE MyByte = 155The answer is: No.Code:MyByte VAR BYTE MyCon CON 155 MyByte = MyCon
The only difference is how you read it as a human. For the PIC and it’s code, they are exactly the same.
I agree but both of the examples use some of the PICs RAM where declaring MYCON CON 155 only would not.
At least that is my understanding.
Bookmarks