[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Accessing structures defined in ROM ?
From: |
Richard Urwin |
Subject: |
Re: [avr-gcc-list] Accessing structures defined in ROM ? |
Date: |
Mon, 26 Sep 2005 18:55:45 +0100 |
User-agent: |
KMail/1.7.2 |
On Monday 26 Sep 2005 17:54, Vincent Trouilliez wrote:
> On Mon, 2005-09-26 at 10:24 -0500, Andy Warner wrote:
> > Vincent Trouilliez wrote:
> > > [...]
> > > i = pgm_read_byte( p->nb ); //should return 3, but doesn't...
> >
> > Try:
> >
> > i = pgm_read_byte(&(p->nb));
> >
> > After all, pgm_read_byte() takes the address of a byte to read,
> > so you need to pass it the _address_ of the object you want.
>
> Thanks Andy and Bernard, that worked. But I don't really understand
> the syntax. Doesn't "p->nb" mean "the address of the element nb
> that's in the structure pointed to by pointer p" ?? So adding a '&'
> means, take the address of that address... passing the address of
> the address of the data....does that make sense ?! :-/
No. p->nb means "the field nb that's pointed to by p".
Hence,
p->nb = p->nb + 1
will increment nb. It will not try (and fail) to increment its address.
p->nb
is equivelant to
(*p).nb
--
Richard Urwin