When using PROGMEM, how to declare variable in the header file?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lets say I want to define the following in the C file:

const uint16_t LCD_W PROGMEM = 240;
const uint16_t LCD_H PROGMEM = 320;

How I declare them in the header file?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Everything but the "= nnn" and with an extern on the front.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Silly question but what's the point of storing them at all. If they were just const int (or whatever) the compiler would optimise them out of existence. No point storing unless you plan to SPM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If they were just const int (or whatever) the compiler would optimise them out of existence

Can you expound upon this a bit?  Certainly if the values of 240 & 320 are actually actively being used, they would still appear or affect the binary code in some form.  I suppose you meant they would be optimized away to the maximum extent possible (which might include complete evaporation). 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In C it's not unusual to just do:

#define WIDTH 320
#define HEIGHT 240

And then whenever you need to make use of the LCD dimension you just use WIDTH and HEIGHT. That still works, but especially in C++ you would tend to use a const in a header for the same purpose but now it has an assigned type and C++ will ensure it can only be assigned to destinations of compatible type. The compiler wont create storage for such values, the value will be used but the variables will be optimised away (no point storing them if they don't change). See

 

http://www.linuxtopia.org/online...