avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] const pointer to progmem?


From: Joerg Desch
Subject: [avr-libc-dev] const pointer to progmem?
Date: Tue, 6 Jun 2006 12:11:04 +0200

I know, it's not (necessary) the right mailing list, but may be you can
help. (The avr-gcc mailing list seems to be dead)

I want to implement a data structure stored inside the progmem. This
structure uses pointer. Within my application, I must use a pointer to the
structure and to some elements inside the structure.

// const pointer (stored in RAM) pointer into progmem
typedef const char __attribute__((__progmem__))* flash_str;

// data structure
struct SAMPLE 
{
    int id;
    flash_str name;
};

// structure completly store in progmem.
struct SAMPLE my_struct[2] __attribute__((__progmem__)) =
{
    {1,"first sample"},
    {2,"another sample"}
};

const struct SAMPLE __attribute__((__progmem__)) * curr_struct;
flash_str curr_name;

void foo (void)
{
    curr_struct = &my_struct[1];
    curr_name = my_struct[1].name;
}

This snippet leads to the error "assignment to write protected variable":

test.c: In Funktion »foo«:
test.c:23: Fehler: Zuweisung der schreibgeschützten Variable »curr_struct«
test.c:24: Fehler: Zuweisung der schreibgeschützten Variable »curr_name«

What's the right way to declare a "const pointer stored in RAM pointing
progmem"?

Can I be sure, that my_struct in the above sample only allocate progmem
(no RAM)?

-- 
Email: Joerg Desch <jd DOT vvd AT web DOT de>





reply via email to

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