//your code
struct CFG config;
struct CFG *cfg_ptr;
//new code
CFG config; //CFG is the type so you don't need to put stuct in front of it
CFG *cfg_ptr;
and this
cfg_ptr = &config;
could be this
cfg_ptr = config;
after that it isn't obvious to me what your using the pointer for as your reading a byte into value from the eprom and then printing it to an LCD. you do assigning something here
(cfg_ptr++) = value;
but without testing it you are assigning the address of the pointer to value (a byte) and then incrementing the pointer by the size of CFG (the whole lot) This wont work i don't think. Unless i'm missing something.
Several problems. Your immediate compilation issue is that you're not de-referencing the pointer, but also, as mentioned above, the ++ is not doing what you expect. It doesn't matter though, because you're setting the pointer back to the initial position in every iteration of your for loop. Try this:
Wildbill
The pointer is of type CFG - of the structure. Will it still point to the structure if I dereference it to a byte.
What I am trying to achieve is to read the eeprom sequentially into the structure. No matter the size of the members (increment the pointer by one byte at a time). This way I can later write longs and floats and pack them byte by byte into the structure. When you then reference the structure, you will read the correct values.
Marius:
Wildbill
The pointer is of type CFG - of the structure. Will it still point to the structure if I dereference it to a byte.
What I am trying to achieve is to read the eeprom sequentially into the structure. No matter the size of the members (increment the pointer by one byte at a time). This way I can later write longs and floats and pack them byte by byte into the structure. When you then reference the structure, you will read the correct values.
I makes no difference really but instead of printing to LCD from value, i would print from the structure. i.e. copy from the eprom to the structure then print from the structure using the pointer and then finally increment it. This way you will be sure that what is in the stuct is the same as the eprom.
Marius:
Thanks for the help guys. It is working fine. I am still slightly confused by the pointer issue but I am sure I will get over it soon.
A pointer is just an address of a location in memory, so whether it's CFG* or byte*, it has the same value. The only difference is that if it's CFG*, the compiler will allow you to directly reference the elements of the struct, which is just a syntactic convenience. Byte* lets you forget about the struct and treat it as the set of contiguous bytes it really is. ptr++ moves to the next element pointed to though, so if it's a byte pointer, it'll increment by one. If it's defined as a pointer to a struct, it'll increment by the size of the struct.
Wildbill,
Thanks man, I did discover what you described. I think my understanding of pointers to structures was not up to scratch. Anyway, the issue is solved and I understand better now. Thanks a lot for the help, it was very constructive and appreciated.