[Top][All Lists]

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

RE: [avr-libc-dev] Problem accessing bytes in program space

From: Wouter van Gulik
Subject: RE: [avr-libc-dev] Problem accessing bytes in program space
Date: Mon, 28 Jan 2008 21:39:25 +0100

>     uart_puts (strcpy_P (buf, (PGM_P)pgm_read_word (&sms_keys[num][2])))
> I'd expect this to print the numth string starting at the 3 character
> (it works as expected in non-embedded normal C).  Am I doing something
> cluelessly wrong, or am I tickling a bug in the compiler?  I'm using
> avr-libc-1.4.6 with avr-gcc 3.4.3 (using a newer version of gcc is a
> bit problematic at the moment...).

Well I think you got it little bit wrong. In written quick out version
you're now doing this:

p = &sms_keys[num];
p+=2;                   //This is not what you want!
                        //You are now pointer to two bytes ahead of
p = pgm_read_word(p);
p = strcpy_P(buf, p);

While you wanted to do this:
p = sms_keys[num];
p = pgm_read_word(p);
p+=2;                           //You want to access bytes 2 of the string
p = strcpy_P(buf, p);

so in your put-all-on-one-line scheme you would get:

uart_puts (strcpy_P (buf, ((PGM_P)pgm_read_word(&sms_keys[num]))[2] ))

I did not test above line, but I hope you get the idea.



reply via email to

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