avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] String array in ROM gives error in spite of following


From: Royce Pereira
Subject: Re: [avr-gcc-list] String array in ROM gives error in spite of following example code.
Date: Mon, 16 Jun 2014 20:53:11 +0530

Thank you, Georg-Johann,
That was very informative !

On Mon, Jun 16, 2014 at 3:28 PM, Georg-Johann Lay <address@hidden> wrote:
> Am 06/12/2014 12:23 PM, schrieb Royce Pereira:
>
>> Hi,
>>
>> I recently updated WinAVR to a newer version of the AVR-GCC toolchain,
>> downloaded from the Atmel site.
>>
>> My version is this:
>>
>> avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.3_1072) 4.8.1
>>
>> My code was compiling without errors before, but with this version, it
>> is giving errors in spite of following the instructions in the faq
>> section of the avr-libc document.
>> //---------------------------------------------
>> #include <avr/io.h>
>> #include <avr/pgmspace.h>
>>
>> const char ptmpUP_msg[]      PROGMEM = "Upper Temp" ;
>> const char ptmpDN_msg[]      PROGMEM = "Lower Temp" ;
>> const char ptmpCLG_msg[]     PROGMEM = "Chiller Temp" ;
>>
>> PGM_P  pgtmp_msg[]    PROGMEM =
>>     { ptmpUP_msg, ptmpDN_msg,  ptmpCLG_msg,} ;
>>
>> //------------------------------------------------------
>> The above code gives the following error:
>>
>> error: variable 'pgtmp_msg' must be const in order to be put into
>> read-only section by means of  '__attribute__((progmem))'
>
>
>
> Read the GCC release notes, it's mentioned in "Caveats":
>
> https://gcc.gnu.org/gcc-4.6/changes.html
>
>
> Just qualify objects that shall go into flash as const.
>
> If you prefer progmem and pgm_read_*, the definitions read:
>
>
> #include <avr/pgmspace.h>
>
> const char ptmpUP_msg[]      PROGMEM = "Upper Temp";
> const char ptmpDN_msg[]      PROGMEM = "Lower Temp";
> const char ptmpCLG_msg[]     PROGMEM = "Chiller Temp";
>
> const char* const pgtmp_msg[]  PROGMEM =
> { ptmpUP_msg, ptmpDN_msg,  ptmpCLG_msg };
>
>
> If you prefer __flash, the definitions read:
>
> const __flash char ptmpUP_msg[]  = "Upper Temp";
> const __flash char ptmpDN_msg[]  = "Lower Temp";
> const __flash char ptmpCLG_msg[] = "Chiller Temp";
>
> const __flash char* const __flash pgtmp_msg[] =
> { ptmpUP_msg, ptmpDN_msg,  ptmpCLG_msg };
>
> pgtmp_msg is const and located in flash.  And it contains elements that are
> pointers to const locations in flash.
>
>
> Johann
>



-- 
Best Regards,

-- Royce Pereira



reply via email to

[Prev in Thread] Current Thread [Next in Thread]