Ok, I have a structure
ZAP* = RECORD
filename : ARRAY 11 OF SYSTEM.BYTE;
attr : SYSTEM.BYTE;
NTRes : SYSTEM.BYTE;
END;
While compiling I get the following: !Length rounded up
Do I run in trouble when reading this from an existing file ?
I need byte aligment and not INTEGER/WORD alignment.
STRUCTURE ALIGNMENT
-
- Site Admin
- Posts: 533
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: STRUCTURE ALIGNMENT
Arrays and records in ARM Oberon-07 are allocated memory in multiples of four bytes. You can use SYSTEM.SIZE to find out how much storage each data type occupies. e.g. SYSTEM.SIZE(ZAP) returns 20 (12 + 4 + 4).
If you are reading data from a binary file created on another system you will need to treat it as a bytestream and do the byte packing yourself. Depending on the origin of the file you may need to consider endian issues as well as alignment.
What you can do is pass a variable of type ZAP to a procedure as a generic output parameter declared as ARRAY OF BYTE. The procedure would input 13 bytes from the file and transfer them to the appropriate bytes of the output parameter.
Examples of the use of ARRAY OF BYTE can be seen in the Astrobe library modules I2C.mod, SPI.mod and Traps.mod.
If you are reading data from a binary file created on another system you will need to treat it as a bytestream and do the byte packing yourself. Depending on the origin of the file you may need to consider endian issues as well as alignment.
What you can do is pass a variable of type ZAP to a procedure as a generic output parameter declared as ARRAY OF BYTE. The procedure would input 13 bytes from the file and transfer them to the appropriate bytes of the output parameter.
Examples of the use of ARRAY OF BYTE can be seen in the Astrobe library modules I2C.mod, SPI.mod and Traps.mod.