simulating_20a_20union
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
simulating_20a_20union [2018/04/17 18:48] – Added syntax highlighting tbest3112 | simulating_20a_20union [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
DIM s1{v%} | DIM s1{v%} | ||
DIM s2{b0&, | DIM s2{b0&, | ||
- | | + | |
s1.v% = & | s1.v% = & | ||
Line 11: | Line 11: | ||
PRINT ~s2.b0& s2.b1& s2.b2& s2.b3& | PRINT ~s2.b0& s2.b1& s2.b2& s2.b3& | ||
</ | </ | ||
- | Here the structure **s1{}** contains the 32-bit integer value **s1.v%** and the structure **s2{}** contains the four 8-bit values **s2.b0& | + | Here the structure **s1{}** contains the 32-bit integer value **s1.v%** and the structure **s2{}** contains the four 8-bit values **s2.b0& |
- | <code bb4w> | + | |
- | DIM s1{v%} | + | |
- | DIM s2{b0&, | + | |
- | PROCunion(s1{}, | + | |
- | + | ||
- | s1.v% = & | + | |
- | + | ||
- | PRINT ~s2.b0& s2.b1& s2.b2& s2.b3& | + | |
- | END | + | |
- | + | ||
- | DEF PROCunion(a{}, | + | |
- | !(^b{}+4) = a{} | + | |
- | ENDPROC | + | |
- | </ | + | |
Note that, unlike languages which have true unions, this technique will not save memory. The memory originally allocated to the structure **s2{}** is wasted, but that doesn' | Note that, unlike languages which have true unions, this technique will not save memory. The memory originally allocated to the structure **s2{}** is wasted, but that doesn' |
simulating_20a_20union.1523990880.txt.gz · Last modified: 2024/01/05 00:16 (external edit)