Re: IAR C-compiler for AVR: Array of pointers to strings in flash

From: Mats Kindahl (mats.kindahl_at_nowhere.net)
Date: 02/03/04


Date: 03 Feb 2004 17:17:42 +0100

Hans-Bernhard Broeker <broeker@physik.rwth-aachen.de> writes:

> Erik Cato <erik.cato@japro.se> wrote:
> > Looking for help from someone with experience with IAR?s C-compiler
> > for AVR (ATmega16/32)
>
> > I want to declare an array with pointers to constant text. And both of
> > the should be in flash-memory, like this.
>
> > __flash char * __flash textTab[] =
> > {
> > "Text1",
> > "Text2",
> > "Text3",
> > "Text4",
> > "Text5",
> > "Text6",
> > "Text7",
> > "Text8",
> > "Text9",
> > };
>
> You forgot to say how this approach failed.
>
> This may just be a bug in that compiler's C extension keyword __flash,
> particularly in how it's parsed, or you may be missing something on
> how it's supposed to be used.

There's a bug in the declaration, it should write:

   char __flash * __flash textTab[] = ....

or
   __flash char __flash * textTab[] = ...

(I know, this is really confusing.)

The reason is that writing a memory attribute first on the line
associates this memory attribute to every variable being declared (for
pre-ANSI backward compatability reasons).
 
The warning message emitted is something about "char const *" not
being convertible to "char __flash *" (not very surprising, they are
in completely different address spaces).

The problem is a result of the fact that, according to the ANSI
standard, generic pointers have to be able to point to string literals
and generic pointers cannot point to flash memory.

Best wishes,
Mats Kindahl

-- 
IAR Systems in Uppsala, Sweden.
Any opinions expressed are my own and not those of my company.
Spam prevention: contact me at mNaOtSkPiAnM@acm.org or
mNaOtSs.kPindAahMl@iar.se, removing the *NO SPAM* from the address.


Relevant Pages

  • Re: Is this math test too easy?
    ... communications glitch; one of the more laughable cartoons ... (A note on "in memory", which for virtual memory machines can get ... Or one can interpret the character string as one of the values ... DOS allowed NULL pointers; the value was in fact interpreted as ...
    (sci.math)
  • [PATCH 2.6.17-rc4 2/6] Some documentation for kmemleak
    ... +Kernel Memory Leak Detector ... +with the difference that the orphan pointers are not freed but only ... +An allocated block of memory is considered orphan if a pointer to its ... The memory allocations hook stores the pointer address together ...
    (Linux-Kernel)
  • [PATCH 2.6.17-rc5 2/7] Some documentation for kmemleak
    ... +Kernel Memory Leak Detector ... +with the difference that the orphan pointers are not freed but only ... +An allocated block of memory is considered orphan if a pointer to its ... The memory allocations hook stores the pointer address together ...
    (Linux-Kernel)
  • [PATCH 2.6.17-rc5 2/7] Some documentation for kmemleak
    ... +Kernel Memory Leak Detector ... +with the difference that the orphan pointers are not freed but only ... +An allocated block of memory is considered orphan if a pointer to its ... The memory allocations hook stores the pointer address together ...
    (Linux-Kernel)
  • [PATCH 2.6.17-rc5 2/8] Some documentation for kmemleak
    ... +Kernel Memory Leak Detector ... +with the difference that the orphan pointers are not freed but only ... +An allocated block of memory is considered orphan if a pointer to its ... The memory allocations hook stores the pointer address together ...
    (Linux-Kernel)