PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

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

 June 26, 2022     avr-gcc, c++, compiler-errors, progmem     No comments   

Issue

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.


Solution

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.



Answered By - kuroi neko
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing