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

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

[avr-gcc-list] Accessing structures defined in ROM ?


From: Vincent Trouilliez
Subject: [avr-gcc-list] Accessing structures defined in ROM ?
Date: Mon, 26 Sep 2005 16:57:56 +0200

Hi list,



I defined a structure in ROM, and am having difficulties accessing it
using a pointer. Structure contains an integer and an array of strings.
Accessing the array works, but when I try to read the integer number
using the pointer, I don't get the correct value.... what am I doing
wrong ?

Compiler doesn't complain of anything, no errors no warning, but it
doesn't retrieve the expected value... :-/

I put a sample code below... any idea ?? I must be doing something wrong
again ! ;-)



Regards,


--
Vince

Using: gcc 3.4.3 and libc 1.2.3



main.c
------

struct menu {
        uint8_t nb;
        char    desc[][20];

};

//definition for the main menu
const struct menu __ATTR_PROGMEM__ menu_main = {
        3,      //there are 3 entries in this menu
        {"-------Main--------",
        "Error Codes",
        "Display Parameters",
        "Data Logging"
        }
};



int main (void){

        uint8_t         i;
        const struct menu * p;

        p = &menu_main;

        i = pgm_read_byte( p->nb ); //should return 3, but doesn't...
        lcd_print_str( p->desc[2] ); //works fine


}


void lcd_print_str(const char * addr)
{
        char c;

        while( (c = pgm_read_byte(addr++)) )
                lcd_putc(c);

}






reply via email to

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