[fpc-pascal] Place of elements in record

Koenraad Lelong fpascal at brouwerij.homelinux.net
Thu Feb 28 08:59:23 CET 2013


I'm developping a arm-embedded project. I need to store some variables 
to EEPROM. What I'm doing now is manually give each variable an address 
and then I use that address to store the variable in EEPROM. 
Unfortunately, that's not easy. Yesterday I spent some hours trying to 
see why the code I wrote does not work. This morning I thought of a 
possible reason, and I think I'm right : I was overlapping some variables.

So I'm trying to find a simpler way to have the relative position of 
variables to use as an address in an EEPROM.
I'm tinking about using a record. Is there a way to get the relative 
position of a record-element ?
Some psuedo-code :

EEPROM_Content : record of
  Var1 : byte;
  Var2 : word;
  Var3 : byte;

EEPROM_WriteByte(<position of Var1 in EEPROM_Content>,EEPROM_Content.Var1);
//<position of Var1 in EEPROM_Content> should be 0
EEPROM_WriteWord(<position of Var2 in EEPROM_Content>,EEPROM_Content.Var2);
//<position of Var2 in EEPROM_Content> should be 1
EEPROM_WriteByte(<position of Var3 in EEPROM_Content>,EEPROM_Content.Var3);
//<position of Var3 in EEPROM_Content> should be 4

I think I could use
@EEPROM_Content.Var1- at EEPROM_Content.Var1
@EEPROM_Content.Var2- at EEPROM_Content.Var1
@EEPROM_Content.Var3- at EEPROM_Content.Var1
as those positions, but is this computed at compile-time, or at run-time 
? Am I right if I assume EEPROM_Content.Var1 is at relative position 0 
in the record ?
I prefer to have the individual variables written to EEPROM, but maybe 
writing the whole record in one go would be possible also. Then I don't 
need to hassle with the positions. I mean, it _is_ possible to do that 
but if it's suited for the project I don't know yet.

Other solutions ?

Mmm, writing things out clears the mind. I think it would be better to 
write the whole record.

Thanks for your input.


Koenraad Lelong

More information about the fpc-pascal mailing list