Go Down

Topic: Please explain this code: *((char*) (Read 749 times) previous topic - next topic

SouthernAtHeart

Trying to understand how to store 5 long numbers in the EEPROM, I'm looking at this page:
Code: [Select]
http://arduino.cc/playground/Code/EEPROMLoadAndSaveSettings

I think I follow it all until I get to this line in Void LoadConfig()
Code: [Select]
*((char*)&storage + t) = EEPROM.read(CONFIG_START + t);

Is storage an array?  What's with the beginning *  --can't find anything on it in the code reference.


westfw

"Treat the address of the long (&storage) as a pointer to a set of bytes instead ((char*)&storage) so that it can be copied from EEPROM (which is byte-wide)  Point to the Tth byte ((char *)&storage +t) and actually put the byte in the ram references by the pointer  (*(char*)&storage +t)"

pocketscience

The leading * dereferences the pointer to the array + offset. This allows you to access the value at that address.


Cheers,
Is life really that serious...??!

SouthernAtHeart

Thanks. 
This cleared it up, after you used the word dereference.  Never heard of any of this, but I kinda understand, now.
http://www.cplusplus.com/doc/tutorial/pointers/


westfw

Quote
cleared it up, after you used the word dereference.

Huh.  And here I carefully avoiding using exactly that word; it hadn't occurred to me that it would be a good search term.  I'll have to remember to consider that...

pocketscience


Quote
cleared it up, after you used the word dereference.

Huh.  And here I carefully avoiding using exactly that word; it hadn't occurred to me that it would be a good search term.  I'll have to remember to consider that...


Me like use big words... ;-)


G.
Is life really that serious...??!

Go Up