-1

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.

6
  • 1
    That annotation doesn't make sense for a function parameter that's a plain value. Overloading on pointer to progmem versus pointer to data memory would make some sense, but that would have to be part of the type of the pointer - can't remember if there's an annotation for that. Commented Jul 31, 2021 at 17:32
  • 2
    PROGMEM is information for the linker where to store the variable. it has nothing to do with the variable type. Commented Jul 31, 2021 at 17:36
  • @Mat my fault on this, i forgot the * before posting it lol Commented Jul 31, 2021 at 17:42
  • @Juraj that's quite sad.. and it's what i was expecting as an answer actually... Commented Jul 31, 2021 at 17:54
  • I was hoping for a workaround though... Commented Jul 31, 2021 at 18:06

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That's a great one! it makes sense for something like const int* variable PROGMEM since PROGMEM, is constant anyways. That was just a "silly" example of mine, in my case i had to store a banch of weights and biases (for readonly purposes if PROGMEM), but at the end i got away with MACROS..
I see. Glad to have been of help :)
0

__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++.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.