My question is more like: Why the compiler "thinks" that a "PROGMEM variable" is the same as a "plain Variable"? is it because PROGMEM-keyword is "just" a macro and nothing more? or is it for some other reason too? and is there any workaround..?
Lets consider the below example:
class object {
public:
object(int* variable);
object(int* variable PROGMEM);
};
it throws error: 'object::object(int*)' cannot be overloaded
as if it is the same.
sketch_jul31a:4:3: error: 'object::object(int*)' cannot be overloaded
object(int* variable PROGMEM)
^~~~~~
sketch_jul31a:3:3: error: with 'object::object(int*)'
object(int* variable)
^~~~~~
exit status 1
'object::object(int*)' cannot be overloaded
I came across this issue a while ago when i was developing a library, I've asked about it on the arduino-forum but i had not any answer and so i've thought after a long period to ask about it once again, here.
You can't expect the compiler to treat linker sections as type qualifiers, but you can define an overload for a const int*
, which is pretty close to the semantics of PROGMEM (a ROM location).
I wonder what you plan on doing with a const int*
though. All you will ever be able to do is read it, so it's basically equivalent to a plain constant int
value, with the added cost of two bytes of ROM.