simulating_20a_20union
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
simulating_20a_20union [2018/03/31 13:19] – external edit 127.0.0.1 | simulating_20a_20union [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
//by Richard Russell, March 2007//\\ \\ BBC BASIC doesn' | //by Richard Russell, March 2007//\\ \\ BBC BASIC doesn' | ||
+ | <code bb4w> | ||
DIM s1{v%} | DIM s1{v%} | ||
DIM s2{b0&, | DIM s2{b0&, | ||
- | | + | |
s1.v% = & | s1.v% = & | ||
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& | + | </ |
- | DIM s1{v%} | + | Here the structure **s1{}** contains the 32-bit integer value **s1.v%** and the structure **s2{}** contains the four 8-bit values **s2.b0& |
- | 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.1522502382.txt.gz · Last modified: 2024/01/05 00:16 (external edit)