ca65-13.html
来自「cc65 的编译器文档」· HTML 代码 · 共 101 行
HTML
101 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.20"> <TITLE>ca65 Users Guide: Structs and unions</TITLE> <LINK HREF="ca65-14.html" REL=next> <LINK HREF="ca65-12.html" REL=previous> <LINK HREF="ca65.html#toc13" REL=contents></HEAD><BODY><A HREF="ca65-14.html">Next</A><A HREF="ca65-12.html">Previous</A><A HREF="ca65.html#toc13">Contents</A><HR><H2><A NAME="structs"></A> <A NAME="s13">13.</A> <A HREF="ca65.html#toc13">Structs and unions</A></H2><P>Structs and unions are special forms of <A HREF="ca65-6.html#scopes">scopes</A>. Theyare to some degree comparable to their C counterparts. Both have a list ofmembers. Each member allocates storage and may optionally have a name, which,in case of a struct, is the offset from the beginning and, in case of a union,is always zero.</P><P>Here is an example for a very simple struct with two members and a total sizeof 4 bytes:</P><P><BLOCKQUOTE><CODE><PRE> .struct Point xcoord .word ycoord .word .endstruct</PRE></CODE></BLOCKQUOTE></P><P>A union shares the total space between all its members, its size is the sameas that of the largest member.</P><P>A struct or union must not necessarily have a name. If it is anonymous, nolocal scope is opened, the identifiers used to name the members are placedinto the current scope instead.</P><P>A struct may contain unnamed members and definitions of local structs. Thestorage allocators may contain a multiplier, as in the example below:</P><P><BLOCKQUOTE><CODE><PRE> .struct Circle .struct Point .word 2 ; Allocate two words .endstruct Radius .word .endstruct</PRE></CODE></BLOCKQUOTE></P><P>Using the <A HREF="ca65-10.html#.TAG">.TAG</A> keyword, it is possible to embeddalready defined structs or unions in structs:</P><P><BLOCKQUOTE><CODE><PRE> .struct Point xcoord .word ycoord .word .endstruct .struct Circle Origin .tag Point Radius .byte .endstruct</PRE></CODE></BLOCKQUOTE></P><P>Space for a struct or union may be allocated using the <A HREF="ca65-10.html#.TAG">.TAG</A> directive.</P><P><BLOCKQUOTE><CODE><PRE> C: .tag Circle</PRE></CODE></BLOCKQUOTE></P><P>Currently, members are just offsets from the start of the struct or union. Toaccess a field of a struct, the member offset has to be added to the addressof the struct itself:</P><P><BLOCKQUOTE><CODE><PRE> lda C+Circle::Radius ; Load circle radius into A</PRE></CODE></BLOCKQUOTE></P><P>This may change in a future version of the assembler.</P><HR><A HREF="ca65-14.html">Next</A><A HREF="ca65-12.html">Previous</A><A HREF="ca65.html#toc13">Contents</A></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?