avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] how is PGM_P supposed to be used?


From: Joerg Wunsch
Subject: Re: [avr-chat] how is PGM_P supposed to be used?
Date: Wed, 8 Jan 2014 11:03:37 +0100 (MET)

Britton Kerin <address@hidden> wrote:

> But this doesn't (prints garbage):
> 
>      PGM_P hello_string = "hello\n";
>      printf_P (hello_string);

Because it produces a string in SRAM, which you then try to
re-interpret as a flash string.  (Of course, it also produces the
initial data for the SRAM string in flash, to be copied over by the
startup code.)

> Which doesn't mention PROGMEM at all?

Before Johann's implementation of named address spaces, the compiler
simply could not know at all whether the data were in flash or RAM;
everything was up to the developer.  The developer had to place the
string manually into flash using PSTR(), and it manually had to take
care the correct (LPM-based) retrieval macros/functions were used.

With named address spaces, and the __flash type qualifier, things are
different.  The compiler then can keep track of the type qualifier,
and it knows it has to use LPM to access the data.
-- 
cheers, Joerg               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)



reply via email to

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