Pages: [1]   Go Down
Author Topic: Please explain this code: *((char*)  (Read 738 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 658
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I think I follow it all until I get to this line in Void LoadConfig()
Code:
*((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.

Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6806
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"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)"
Logged

Sydney, Australia
Offline Offline
Full Member
***
Karma: 3
Posts: 230
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Cheers,
Logged

Is life really that serious...??!

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 658
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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/

Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6806
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Sydney, Australia
Offline Offline
Full Member
***
Karma: 3
Posts: 230
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Is life really that serious...??!

Pages: [1]   Go Up
Jump to: