How to make these PROGMEM warnings go away?

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

To my surprise I haven't been able to find an answer to this - maybe I don't search well...

Anyway, I'm trying to do something fairly common, I presume: put some data (structs) into progmem, and put an array of pointers to those structs in progmem as well. Like this:

typedef struct ST_S
{
	int i1;
	int i2;
} ST;


ST S1 PROGMEM = { 1, 2 };
ST S2 PROGMEM = { 3, 4 };
ST S3 PROGMEM = { 5, 6 };
ST S4 PROGMEM = { 7, 8 };

ST * ST_array[] PROGMEM = { &S1, &S2, &S3, &S4 };

I can see from the list file that the structs and the array go into progmem correctly, and the array is correctly filled. But I get this warning, which I'd like to eliminate:

../Test.c:19: warning: initialization discards qualifiers from pointer target type

Line 19 is the ST_array line. What am I doing wrong?

Mike

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

kk6gm wrote:
What am I doing wrong?
I do not know ... but I think you can make it go away if you add "const" to line 19.

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

kk6gm wrote:

typedef struct ST_S
{
	int i1;
	int i2;
} ST;


ST S1 PROGMEM = { 1, 2 };
ST S2 PROGMEM = { 3, 4 };
ST S3 PROGMEM = { 5, 6 };
ST S4 PROGMEM = { 7, 8 };

ST * ST_array[] PROGMEM = { &S1, &S2, &S3, &S4 };

I can see from the list file that the structs and the array go into progmem correctly, and the array is correctly filled. But I get this warning, which I'd like to eliminate:

../Test.c:19: warning: initialization discards qualifiers from pointer target type

Qualifier means const or volatile.
Volatile would be really hard to understand,
so it must be const.
You don't have const either.
The only thing I can think of is that
PROGMEM might be implicitly const.
In that case, put a const in front of the last declaration.

Moderation in all things. -- ancient proverb

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

"const" does indeed solve the warning. Thanks.

Mike