Can "only inititialized vars in pgm space" warning

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

I'm updating some old AVR C code that's been building with gcc ver 3.4.3, trying to get it to compile cleanly with ver 4.2.2.

Everything goes well except that several places where I've tried to use tables of function pointers in PROGMEM as part of a crude command decoding mechanism provokes the following warning messge from the compiler:

warning: only initialized variables can be placed into program memory area

I've spent a couple hours looking through the forums and tutorials. Although I did find one other posting that mentioned this warning message, I didn't see any answer to the question of whether this warning message is a legitimate one, and, if so, how the offending source code could be changed to prevent the warning. Is there advice on this point?

Thanks in advance!

Attachment(s): 

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

Hi,
I tried to compile the code and it compiles smoothly without any warning message.

Looks like the problem is in your compiler. Try to re-install the compiler tool chain.

KISS - Keep It Simple Stupid!

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

Your code compiles ok here (4.2.2). A few changes were made to get your code to compile, but those changes were not related to the problem (adding main, making those extern functions just empty functions).

I assume the warning refers to function table progmem line and not some other progmem line you are using.

if you do something like this-
static const uint8_t test PROGMEM;

you will get this warning-
warning: only initialized variables can be placed into program memory area

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

Thanks to m23402027 and curtvm for their pointers and help. As the first responder suggested, I un- and re-installed WinAVR-20071221, but the strange warning message was still presented.

It then occurred to me that I was using the old project's Makefile to try and build under the new toolchain. A fresh makefile skeleton generated by Astudio seemed significantly different than the old one, so I've spent awhile trying to understand the new style (sheesh - "make" is astonishingly complicated). After rewriting the old Makefile in the "new style" (the project doesn't quite fit the assumptions of AStudio's automatically generated makefile), I got the same error message, plus one new one, complaining that the "-std=gnu99" compiler option was inappropriate for a C++ source file.

Click! It hit me then that all my source files had ".cpp" extensions (habitual conformance to the practices of the department I work in). I changed the extensions to be ".c", and THAT eliminated the compiler warning.

Thanks again, everyone.

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

Quote:
Click! It hit me then that all my source files had ".cpp" extensions (habitual conformance to the practices of the department I work in). I changed the extensions to be ".c", and THAT eliminated the compiler warning.

Heh? That kind of different extention affects compiler that much? Hmm, gain new knowledge today :mrgreen:

KISS - Keep It Simple Stupid!

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

Question.

did jou just hit 'build' in Astudio or rebuild ?

A have noticed that warnings tend to dis appear after a build and resurface when doing a rebuild all.

so it might went below surface for now until you do a rebuild and getting crazy for a warning that should not have been there suddenly pops up...

regards

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

meslomp wrote:
A have noticed that warnings tend to dis appear after a build and resurface when doing a rebuild all.

so it might went below surface for now until you do a rebuild and getting crazy for a warning that should not have been there suddenly pops up...

This is not strange. The warning is only generated when it compiles the specific file. And not all files are compiled every time.

for example: It can happen when you have multiple sourcefiles. Let's say you have foo.c and bar.c. When compiling foo.c it gives a warning. But foo.o (out file) is saved. When you make a change to bar.c and then compile again, foo.c won't be compiled again, because the source file didn't change. So the warning isn't showed now. When chaning something in foo.c (or rebuild all) the warning will be shown off course.

HTH

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

That is what I already thought, but as so many others...

I'm a relative newbee in sofware/firmware embedded ware so did not know for sure that this waws te case.

thanks for the information

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

I get the same error(s), but i don't want to rename cpp files to c because they contain c++ code.

I've ignored them for a while, but they are very annoying and make other warnings hard to notice. Isn't there any other solution?

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

totenhose wrote:
I get the same error(s), but i don't want to rename cpp files to c because they contain c++ code.

I've ignored them for a while, but they are very annoying and make other warnings hard to notice. Isn't there any other solution?

Usually, one can make a warning go away by making it inapplicable.
Do you have uninitialized variables in program memory?
An element of an array or structure, perhaps?

If not, you are fighting a compiler bug.
A work around might be to put the variable in a *.c file.

Iluvatar is the better part of Valar.

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

Quote:

Heh? That kind of different extention affects compiler that much? Hmm, gain new knowledge today Mr. Green

One incarnates the C++ compiler, and the other the regular C compiler. C++ and C differ in some respects (for example, "const" in C++ means what you think it means, while in C it only indicates that something is read-only), one of which must be triggering the warning.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

That is a known problem with the C++ compiler. The code works so I just ignore it.
https://www.avrfreaks.net/index.p...

Actually you are lucky. I not only get this warning, but I'm also told my code is dangerous. :) I think the "dangerous" warning is being fixed. I'm not sure about the other one.

lcd_driver.cpp:19: warning: only initialized variables can be placed into program memory area
D:\WINDOWS\TEMP/ccbLsPvb.s: Assembler messages:
D:\WINDOWS\TEMP/ccbLsPvb.s:476: Warning: expression dangerous with linker stubs
D:\WINDOWS\TEMP/ccbLsPvb.s:477: Warning: expression dangerous with linker stubs

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

steve17 wrote:
That is a known problem with the C++ compiler. The code works so I just ignore it.
https://www.avrfreaks.net/index.p...
The obvious work-around is to use C, if one can, to put data in program memory.

Iluvatar is the better part of Valar.