Hi, On Sun, Dec 6, 2009 at 4:20 AM, darkschine <zhpctw3d...@hotmail.com> wrote: > > This topic is covered all over avr forums in bits and pieces so please keep > responses to a minimum. The problem is that when using PSTR("String") in a > cpp file, the compiler generates the warning: > > warning: only initialized variables can be placed into program memory area ...snip...
> Does anyone have a proven solution or workaround for this problem? Is there > anything that can be done to at least suppress the warning without > suppressing other warnings? I think I found a way. I tested this with WinAVR-20080610 (gcc 4.3.0) and with the latest (WinAVR-20090313 gcc 4.3.2). My source file, called test.cpp was as follows: ----- Start of test.cpp ----- #include <avr/pgmspace.h> #if 0 #undef PROGMEM #define PROGMEM __attribute__(( section(".progmem.data") )) #undef PSTR #define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) #endif void Log_P( const char *fmt, ... ); void foo( void ) { Log_P( PSTR( "foo was called\n" )); } ----- End of test.cpp ----- As shown above, I compiled it with the following command line: 603 >avr-g++ -mmcu=atmega168 -c test.cpp -o test1.o test.cpp: In function 'void foo()': test.cpp:15: warning: only initialized variables can be placed into program memory area and then ran 604 >avr-objdump --full-contents test1.o test1.o: file format elf32-avr Contents of section .text: 0000 df93cf93 cdb7deb7 80e090e0 00d0edb7 ................ 0010 feb73196 91838083 0e940000 0f900f90 ..1............. 0020 cf91df91 0895 ...... Contents of section .progmem.data: 0000 666f6f20 77617320 63616c6c 65640a00 foo was called.. I then changed the #if 0 to #if 1 and repeated, replacing test1.o with test2.o 605 >avr-g++ -mmcu=atmega168 -c test.cpp -o test2.o 606 >avr-objdump --full-contents test2.o test2.o: file format elf32-avr Contents of section .text: 0000 df93cf93 cdb7deb7 80e090e0 00d0edb7 ................ 0010 feb73196 91838083 0e940000 0f900f90 ..1............. 0020 cf91df91 0895 ...... Contents of section .progmem.data: 0000 666f6f20 77617320 63616c6c 65640a00 foo was called.. 607 >cmp test1.o test2.o shows that the two objects are in fact 100% identical, but the 2nd version has no warning. -- Dave Hylands Shuswap, BC, Canada http://www.DaveHylands.com/ _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list