Why AVR-GCC compiler throws an error when overloading with the same variables but as PROGMEM?

195 views Asked by At

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..?

ISSUE demonstration:

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

Outro:

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.

2

There are 2 answers

2
kuroi neko On BEST ANSWER

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.

0
273K On

__attribute__((progmem)) is a compiler feature, not a C++ language feature, so it does not participate in the overload resolution. The both object(int variable); and object(int variable PROGMEM); looks like the double declaration of object(int variable); in terms of C++.