Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: need variables to be stored in EEPROM

2005-04-25 by David Kelly

On Mon, Apr 25, 2005 at 07:16:15PM -0000, arhodes19044 wrote:
> 
> Yes, I can see that the structure will provide a convenient 
> technique to read & write the entire block.
> 
> It has been a long time since I worked with structures.  Is there a 
> way to get the offset of the element within the structure?  
> Something like "&structure.element".  This way, I can start with the 
> location of the structure in SRAM or in EEPROM and then access the 
> individual element by base + offset.  Will sizeof() work with 
> structure elements?

Yes, and yes.

But remember if one tries (&structure.element - &structure) pointer
arithmetic may come into play. Make casts to (size_t) before doing the
math. Thats the point of the offsetof() macro mentioned.

#define offsetof(type, field) ((size_t)(&((type *)0)->field))

For the above to work your structure has to be in a typedef.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.