mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
using less generic names for the example to avoid confusion, adding cautionary example for what I think is the most error prone case
This commit is contained in:
parent
302c4f7409
commit
9892c8f6c4
@ -5003,23 +5003,29 @@ continuing through that scope. Example:
|
|||||||
|
|
||||||
<tscreen><verb>
|
<tscreen><verb>
|
||||||
.struct Object
|
.struct Object
|
||||||
member .byte ; Object::member = 0
|
id .byte ; Object::id = 0
|
||||||
named .struct Point ; Object::named = 1
|
target .struct Point ; Object::target = 1
|
||||||
xcoord .word ; Object::Point::xcoord = 0
|
xcoord .word ; Object::Point::xcoord = 0
|
||||||
ycoord .word ; Object::Point::ycoord = 2
|
ycoord .word ; Object::Point::ycoord = 2
|
||||||
.endstruct
|
.endstruct
|
||||||
unnamed .struct ; Object::unnamed = 5
|
cost .struct ; Object::cost = 5
|
||||||
un1 .word ; Object::un1 = 5
|
price .word ; Object::price = 5
|
||||||
un2 .word ; Object::un2 = 7
|
tax .word ; Object::tax = 7
|
||||||
.endstruct
|
.endstruct
|
||||||
.struct
|
.struct
|
||||||
un3 .word ; Object::un3 = 9
|
radius .word ; Object::radius = 9
|
||||||
.endstruct
|
.endstruct
|
||||||
.endstruct
|
.endstruct
|
||||||
|
|
||||||
O: .tag Object
|
O: .tag Object
|
||||||
lda O + Object::named + Object::Point::ycoord
|
lda O + Object::target + Object::Point::ycoord ; Named struct
|
||||||
lda O + Object::un2
|
lda O + Object::tax ; Anonymous
|
||||||
|
lda O + Object::radius ; Anonymous
|
||||||
|
|
||||||
|
; Be careful not to use a named nested structure without also adding the
|
||||||
|
; offset to the nested structure itself.
|
||||||
|
lda O + Object::Point::ycoord ; Incorrect!
|
||||||
|
lda O + Object::target + Object::Point::ycoord ; Correct
|
||||||
</verb></tscreen>
|
</verb></tscreen>
|
||||||
|
|
||||||
In this example, the first nested structure is named "Point", and its member
|
In this example, the first nested structure is named "Point", and its member
|
||||||
@ -5027,8 +5033,8 @@ offsets begin at 0. On the other hand, the two anonymous structures simply
|
|||||||
continue to add members to the enclosing "Object" structure.
|
continue to add members to the enclosing "Object" structure.
|
||||||
|
|
||||||
Note that an anonymous structure does not need a member name, since all of its
|
Note that an anonymous structure does not need a member name, since all of its
|
||||||
members become part of the enclosing structure. The "unnamed" member in the
|
members become part of the enclosing structure. The "cost" member in the
|
||||||
example is redundantly the same offset as its first member "un1".
|
example is redundantly the same offset as its first member "price".
|
||||||
|
|
||||||
|
|
||||||
<sect1>Limitations<p>
|
<sect1>Limitations<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user