aligning_20structures
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
aligning_20structures [2018/04/17 15:01] – Added syntax highlighting tbest3112 | aligning_20structures [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 6: | Line 6: | ||
<code bb4w> | <code bb4w> | ||
DIM mystruct{member1, | DIM mystruct{member1, | ||
- | | + | |
</ | </ | ||
When the structure is declared, a dummy member **padding%** is added at the very end; this allows the structure to be moved up in memory by 4 bytes, if necessary, without corrupting subsequent memory contents; //it is vitally important that this member is never written//! The second line adjusts the address of the structure so that it is a multiple of eight.\\ \\ If you want to align the structure at a multiple-of-16 address the padding needs to be 12 bytes in size, most easily arranged by making it an array: | When the structure is declared, a dummy member **padding%** is added at the very end; this allows the structure to be moved up in memory by 4 bytes, if necessary, without corrupting subsequent memory contents; //it is vitally important that this member is never written//! The second line adjusts the address of the structure so that it is a multiple of eight.\\ \\ If you want to align the structure at a multiple-of-16 address the padding needs to be 12 bytes in size, most easily arranged by making it an array: | ||
<code bb4w> | <code bb4w> | ||
DIM mystruct{member1, | DIM mystruct{member1, | ||
- | | + | |
</ | </ | ||
\\ | \\ | ||
Line 19: | Line 19: | ||
DIM mystruct{member1, | DIM mystruct{member1, | ||
DIM newdata% DIM(mystruct{})+6 | DIM newdata% DIM(mystruct{})+6 | ||
- | | + | |
</ | </ | ||
Similarly to align it on a multiple-of-16 address: | Similarly to align it on a multiple-of-16 address: | ||
Line 25: | Line 25: | ||
DIM mystruct{member1, | DIM mystruct{member1, | ||
DIM newdata% DIM(mystruct{})+14 | DIM newdata% DIM(mystruct{})+14 | ||
- | | + | |
</ | </ | ||
Note that you must declare the structure using this method **only once** and not repeat the above code (for example in a loop).\\ \\ If declaring a structure for local use in a procedure or function, use **DIM LOCAL**: | Note that you must declare the structure using this method **only once** and not repeat the above code (for example in a loop).\\ \\ If declaring a structure for local use in a procedure or function, use **DIM LOCAL**: | ||
Line 32: | Line 32: | ||
DIM mystruct{member1, | DIM mystruct{member1, | ||
DIM newdata% LOCAL DIM(mystruct{})+6 | DIM newdata% LOCAL DIM(mystruct{})+6 | ||
- | | + | |
</ | </ |
aligning_20structures.1523977269.txt.gz · Last modified: 2024/01/05 00:18 (external edit)