Compatibility: the `init' function no longer calls `imprint' for you.
[sod] / lib / sod-structs.3
CommitLineData
47de28ae
MW
1.\" -*-nroff-*-
2.\"
3.\" Description of the main Sod data structures
4.\"
5.\" (c) 2015 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
e0808c47 10.\" This file is part of the Sensible Object Design, an object system for C.
47de28ae
MW
11.\"
12.\" SOD is free software; you can redistribute it and/or modify
65aaa02c
MW
13.\" it under the terms of the GNU Library General Public License as
14.\" published by the Free Software Foundation; either version 2 of the
15.\" License, or (at your option) any later version.
47de28ae
MW
16.\"
17.\" SOD is distributed in the hope that it will be useful,
18.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65aaa02c 20.\" GNU Library General Public License for more details.
47de28ae 21.\"
65aaa02c
MW
22.\" You should have received a copy of the GNU Library General Public
23.\" License along with SOD; if not, write to the Free
24.\" Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25.\" MA 02111-1307, USA.
47de28ae 26.
9ed8eb2a 27.\" Highlight using terminal escapes, rather than overstriking.
47de28ae 28.\"\X'tty: sgr 1'
9ed8eb2a 29.
47de28ae
MW
30.\" String definitions and font selection.
31.ie t \{\
32. ds o \(bu
33. if \n(.g .fam P
34.\}
35.el \{\
36. ds o o
37.\}
38.
39.\" .hP TEXT -- start an indented paragraph with TEXT hanging off to the left
40.de hP
41.IP
42\h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
43..
44.
45.\"--------------------------------------------------------------------------
46.TH sod-structs 3 "8 September 2015" "Straylight/Edgeware" "Sensible Object Design"
47.
48.SH NAME
49sod-structs \- main Sod data structures
50.
51.\"--------------------------------------------------------------------------
52.SH SYNOPSIS
53.nf
54.ft B
55#include <sod/sod.h>
56
57typedef struct SodObject__ichain_obj SodObject;
58typedef struct SodClass__ichain_obj SodClass;
59
60struct sod_instance {
61\h'2n'const struct sod_vtable *_vt;
62};
63
64struct sod_vtable {
65\h'2n'const SodClass *_class;
66\h'2n'size_t _base;
67};
68
69struct SodObject__vt_obj {
70\h'2n'const SodClass *_class;
71\h'2n'size_t _base;
72};
73
74struct SodObject__ilayout {
75\h'2n'union {
76\h'4n'struct SodObject__ichain_obj {
77\h'6n'const struct SodObject__vt_obj *_vt;
78\h'4n'};
79\h'2n'} obj;
80};
81
82extern const struct SodClass__ilayout SodObject__classobj;
83#define SodObject__class (&SodObject__classobj.obj.cls)
84
85struct SodClass__vt_obj {
86\h'2n'const SodClass *_class;
87\h'2n'size_t _base;
88};
89
90struct SodObject__ilayout {
91\h'2n'union {
92\h'4n'struct SodClass__ichain_obj {
93\h'6n'const struct SodClass__vt_obj *_vt;
94\h'6n'struct SodClass__islots {
95\h'8n'const char *name;
96\h'8n'const char *nick;
97\h'8n'size_t initsz;
98\h'8n'void *(*imprint)(void *\fIp\fB);
99\h'8n'void *(*init)(void *\fIp\fB);
100\h'8n'size_t n_supers;
101\h'8n'const SodClass *const *supers;
102\h'8n'size_t n_cpl;
103\h'8n'const SodClass *const *cpl;
104\h'8n'const SodClass *link;
105\h'8n'const SodClass *head;
106\h'8n'size_t level;
107\h'8n'size_t n_chains;
108\h'8n'const struct sod_chain *chains;
109\h'8n'size_t off_islots;
110\h'8n'size_t islotsz;
111\h'6n'} cls;
112\h'4n'};
113\h'4n'SodObject obj;
114\h'2n'} obj;
115};
116
117struct sod_chain {
118\h'2n'size_t n_classes;
119\h'2n'const SodClass *const *classes;
120\h'2n'size_t off_ichain;
121\h'2n'const struct sod_vtable *vt;
122\h'2n'size_t ichainsz;
123};
124
125extern const struct SodClass__ilayout SodClass__classobj;
126#define SodClass__class (&SodClass__classobj.obj.cls)
127.fi
128.ft P
129.
130.\"--------------------------------------------------------------------------
131.SH DESCRIPTION
132.
133This page describes the structure and layout
134of standard Sod objects, classes and associated metadata.
135Note that Sod's object system is very flexible
136and it's possible for an extension
137to define a new root class
138which works very differently from the standard
139.B SodObject
140described here.
141.
142.\"--------------------------------------------------------------------------
143.SH COMMON INSTANCE STRUCTURE
144.
145As described below,
146a pointer to an instance actually points to an
147.I "instance chain"
148structure within the instances overall layout structure.
149.PP
150Instance chains contain slots and vtable pointers,
151as described below.
152All instances have the basic structure of a
153.BR "struct sod_instance" ,
154which has the following members.
155.TP
156.B "const struct sod_vtable *_vt"
157A pointer to a
158.IR vtable ,
159which has the basic structure of a
160.BR "struct sod_vtable" ,
161described below.
162.PP
163A vtable contains static metadata needed
164for efficient conversions and
165message dispatch,
166and pointers to the instance's class.
167Each chain points to a different vtable
168All vtables have the basic structure of a
169.BR "struct sod_vtable" ,
170which has the following members.
171.TP
172.B "const SodClass *_class"
173A pointer to the instance's class object.
174.TP
175.B "size_t _base;"
176The offset of this chain structure
177above the start of the overall instance layout, in bytes.
178Subtracting
179.B _base
180from the instance chain pointer
181finds the layout base address.
182.
183.\"--------------------------------------------------------------------------
184.SH BUILT-IN ROOT OBJECTS
185.
186This section describes the built-in classes
187.B SodObject
188and
189.BR SodClass ,
190which are the standard roots of the inheritance and metaclass graphs
191respectively.
192Specifically,
193.B SodObject
194has no direct superclasses,
195and
196.B SodClass
197is its own metaclass.
9c4a4110
MW
198It is not possible to define root classes in module files
199because of circularities:
47de28ae
MW
200.B SodObject
201has
202.B SodClass
9c4a4110
MW
203as its metaclass,
204and
47de28ae
MW
205.B SodClass
206is a subclass of
207.BR SodObject .
208Extensions can define additional root classes,
209but this is tricky,
210and not really to be recommended.
211.
212.SS The SodObject class
213The
214.B SodObject
215class defines no slots or messages.
216Because
217.B SodObject
218has no direct superclasses,
219there is only one chain,
220and no inherited slots or messages,
221so the single chain contains only a vtable pointer.
222.PP
223Since there are no messages,
224and
225.B SodClass
226also has only one chain,
227the vtable contains only the standard class pointer and offset-to-base
228members.
229In an actual instance of
230.B SodObject
231(why would you want one?)
232the class pointer contains the address of
233.B SodObject__class
234and the offset is zero.
235.
236.SS The SodClass class
237The
238.B SodClass
239class defines no messages,
240but there are a number of slots.
241Its only direct superclass is
242.B SodObject
243and so (like its superclass) its vtable is trivial.
244.PP
245The slots defined are as follows.
246.TP
247.B const char *name;
248A pointer to the class's name.
249.TP
250.B const char *nick;
251A pointer to the class's nickname.
252.TP
253.B size_t initsz;
254The size in bytes required to store an instance of the class.
255.TP
256.BI "void *(*imprint)(void *" p );
257A pointer to a function:
258given a pointer
259.I p
260to at least
261.I initsz
262bytes of appropriately aligned memory,
263`imprint' this memory it so that it becomes a minimally functional
264instance of the class:
265all of the vtable and class pointers are properly initialized,
266but the slots are left untouched.
267The function returns its argument
268.IR p .
269.TP
270.BI "void *(*init)(void *" p );
271A pointer to a function:
272given a pointer
273.I p
54fa3df9
MW
274to an imprinted instance,
275initialize all of its slots for which initializers are defined.
47de28ae
MW
276Other slots are left untouched.
277The function returns its argument
278.IR p .
279.TP
280.B size_t n_supers;
281The number of direct superclasses.
282(This is zero exactly in the case of
283.BR SodObject .)
284.TP
285.B const SodClass *const *supers;
286A pointer to an array of
287.I n_supers
288pointers to class objects
289listing the class's direct superclasses,
290in the order in which they were listed in the class definition.
291If
292.I n_supers
293is zero,
294then this pointer is null.
295.TP
296.B size_t n_cpl;
297The number of superclasses in the class's class precedence list.
298.TP
299.B const SodClass *const *cpl;
300A pointer to an array of pointers to class objects
301listing all of the class's superclasses,
302from most- to least-specific,
303starting with the class itself,
304so
305.IB c ->cls.cpl[0]
306=
307.I c
308for all class objects
309.IR c .
310.TP
311.B const SodClass *link;
312If the class is a chain head, then this is a null pointer;
313otherwise it points to the class's distinguished link superclass
314(which might or might not be a direct superclass).
315.TP
316.B const SodClass *head;
317A pointer to the least-specific class in this class's chain;
318so
319.IB c ->cls.head->cls.link
320is always null,
321and either
322.IB c ->cls.link
323is null
324(in which case
325.IB c ->cls.head
326=
327.IR c )
328or
329.IB c ->cls.head
330=
331.IB c ->cls.link->cls.head \fR.
332.TP
333.B size_t level;
334The number of less specific superclasses in this class's chain.
335If
336.IB c ->cls.link
337is null then
338.IB c ->cls.level
339is zero;
340otherwise
341.IB c ->cls.level
342=
343.IB c ->cls.link->cls.level
344+ 1.
345.TP
346.B size_t n_chains;
347The number of chains formed by the class's superclasses.
348.TP
349.B const struct sod_chain *chains;
350A pointer to an array of
351.B struct sod_chain
352structures (see below) describing the class's superclass chains,
353in decreasing order of specificity of their most specific classes.
354It is always the case that
355.IB c ->cls.chains[0].classes[ c ->cls.level]
356=
357.IR c .
358.TP
359.B size_t off_islots;
360The offset of the class's
361.B islots
362structure relative to its containing
363.B ichain
364structure.
365The class doesn't define any slots if and only if this is zero.
366(The offset can't be zero because the vtable pointer is at offset zero.)
367.TP
368.B size_t islotsz;
369The size required to store the class's direct slots,
370i.e., the size of its
371.B islots
372structure.
373The class doesn't define any slots if and only if this is zero.
374.PP
375The
376.B struct sod_chain
377structure describes an individual chain of superclasses.
378It has the following members.
379.TP
380.B size_t n_classes;
381The number of classes in the chain.
382This is always at least one.
383.TP
384.B const SodClass *const *classes;
385A pointer to an array of class pointers
386listing the classes in the chain from least- to most-specific.
387So
388.IB classes [ i ]->cls.head
389=
390.IB classes [0]
391for all
3920 \(<=
393.I i
394<
395.IR n_classes ,
396.IB classes [0]->cls.link
397is always null,
398and
399.IB classes [ i ]->cls.link
400=
401.IB classes [ "i\fR \- 1" ]
402if
4031 \(<=
404.I i
405<
406.IR n_classes .
407.TP
408.B size_t off_ichain;
409The size of the
410.B ichain
411structure for this chain.
412.TP
413.B const struct sod_vtable *vt;
414The vtable for this chain.
415(It is possible, therefore, to duplicate the behaviour of the
416.I imprint
417function by walking the chain structure.
418The
419.I imprint
420function is much faster, though.)
421.TP
422.B size_t ichainsz;
423The size of the
424.B ichain
425structure for this chain.
426.
427.\"--------------------------------------------------------------------------
428.SH CLASS AND VTABLE LAYOUT
429.
430The layout algorithms for Sod instances and vtables are nontrivial.
431They are defined here in full detail,
432since they're effectively fixed by Sod's ABI compatibility guarantees,
433so they might as well be documented for the sake of interoperating
434programs.
435.PP
436Unfortunately, the descriptions are rather complicated,
437and, for the most part not necessary to a working understanding of Sod.
438The skeleton structure definitions shown should be more than enough
439for readers attempting to make sense of the generated headers and tables.
440.PP
441In the description that follows,
442uppercase letters vary over class names,
443while the corresponding lowercase letters indicate the class nicknames.
444Throughout, we consider a class
445.I C
446(therefore with nickname
447.IR c ).
448.
449.SS Generic instance structure
450The entire state of an instance of
451.I C
452is contained in a single structure of type
453.B struct
454.IB C __ilayout \fR.
455.IP
456.nf
457.ft B
458struct \fIC\fB__ilayout {
459\h'2n'union \fIC\fB__ichainu_\fIh\fB {
460\h'4n'struct \fIC\fB__ichain_\fIh\fB {
461\h'6n'const struct \fIC\fB__vt_\fIh\fB *_vt;
462\h'6n'struct \fIH\fB__islots \fIh\fB;
463\h'6n'\fR...\fB
464\h'6n'struct \fIC\fB__islots {
465\h'8n'\fItype\fB \fIslota\fB;
466\h'8n'\fR...\fB
467\h'6n'} \fIc\fB;
468\h'4n'} \fIc\fB;
469\h'4n'\fR...\fB
470\h'4n'struct \fIH\fB__ichain_\fIh\fB \fIh\fB;
471\h'2n'} \fIh\fB;
472\h'2n'union \fIB\fB__ichainu_\fIi\fB \fIi\fB;
473\h'2n'\fR...\fB
474};
475
476typedef struct \fIC\fB__ichain_\fIh\fB \fIC\fB;
477.ft P
478.fi
479.PP
480The set of superclasses of
481.IR C ,
482including itself,
483can be partitioned into chains
484by following their distinguished superclass links.
485(Formally, the chains are the equivalence classes determined by
486the reflexive, symmetric, transitive closure of
487the `links to' relation.)
488Chains are identified by naming their least specific classes;
489the least specific class in a chain is called the
490.IR "chain head" .
491Suppose that the chain head of the chain containing
492.I C
493itself is named
494.I H
495(though keep in mind that it's possible that
496.I H
497is in fact
498.I C
499itself.)
500.PP
501The
502.B ilayout
503structure contains one member for each of
504.IR C 's
505superclass chains.
506The first such member is
507.IP
508.B
509.B union
510.IB C __ichainu_ h
511.IB h ;
512.PP
513described below;
514this is followed by members
515.IP
516.B union
517.IB B __ichainu_ i
518.IB i ;
519.PP
520for each other chain,
521where
522.I I
523is the head
524and
525.I B
526the tail (most-specific) class of the chain.
527The members are in decreasing order
528of the specificity of the chains' most-specific classes.
529(Note that all but the first of these unions
530has already been defined as part of
531the definition of the corresponding
532.IR B .)
533.PP
534The
535.B ichainu
536union contains a member for each class in the chain.
537The first is
538.IP
539.B struct
540.IB C __ichain_ h
541.IB c ;
542.PP
543and this is followed by corresponding members
544.IP
545.B struct
546.IB A __ichain_ h
547.IB a ;
548.PP
549for each of
9c4a4110
MW
550.IR C 's
551superclasses
47de28ae
MW
552.IR A
553in the same chain in some (unimportant) order.
554A `pointer to
555.IR C '
556is always assumed
557(and, indeed, defined in C's type system)
558to be a pointer to the
559.B struct
560.IB C __ichain_ h \fR.
561.PP
562The
563.B ichain
564structure contains (in order), a pointer
565.IP
566.B const
567.B struct
568.IB C __vt_ h
569.B *_vt;
570.PP
571followed by a structure
572.IP
573.B struct
574.IB A __islots
575.IB a ;
576.PP
577for each superclass
578.I A
579of
580.IR C
581in the same chain which defines slots,
582from least- to most-specific;
583if
584.I C
585defines any slots,
586then the last member is
587.IP
588.B struct
589.IB C __islots
590.IB c ;
591.PP
592Finally, the
593.B islots
594structure simply contains one member for each slot defined by
595.I C
596in the order they appear in the class definition.
597.
598.SS Generic vtable structure
599As described above,
600each
601.B ichain
602structure of an instance's storage
603has a vtable pointer
604.IP
605.B const
606.B struct
607.IB C __vt_ h
608.B *_vt;
609.PP
610In general,
611the vtables for the different chains
612will have
613.I different
614structures.
615.PP
616The instance layout split neatly into disjoint chains.
617This is necessary because
618each
619.B ichain
620must have as a prefix the
621.B ichain
9c4a4110
MW
622for each superclass in the same chain,
623and each slot must be stored in exactly one place.
47de28ae
MW
624The layout of vtables doesn't have this second requirement:
625it doesn't matter that there are
626multiple method entry pointers
627for the same effective method
628as long as they all work correctly.
9c4a4110
MW
629Indeed, it's essential that they do,
630because each chain's method entry function
631will need to apply a different offset to the receiver pointer
632before invoking the effective method.
47de28ae
MW
633.PP
634A vtable for a class
635.I C
636with chain head
637.I H
638has the following general structure.
639.IP
640.nf
641.ft B
642union \fIC\fB__vtu_\fIh\fB {
643\h'2n'struct \fIC\fB__vt_\fIh\fB {
644\h'4n'const \fIP\fB *_class;
645\h'4n'size_t _base;
646\h'4n'\fR...\fB
647\h'4n'const \fIQ\fB *_cls_\fIj\fB;
648\h'4n'\fR...\fB
649\h'4n'ptrdiff_t _off_\fIi\fB;
650\h'4n'\fR...\fB
651\h'4n'struct \fIC\fB__vtmsgs_\fIa\fB {
652\h'6n'\fItype\fB (*\fImsg\fB)(\fIC\fB *, \fR...\fB);
653\h'6n'\fR...\fB
654\h'4n'} \fIa\fB;
655\h'4n'\fR...\fB
656\h'2n'} \fIc\fB;
657};
658
659extern const union \fIC\fB__vtu_\fIh\fB \fIC\fB__vtable_\fIh\fB;
660.ft P
661.fi
662.PP
663The outer layer is a
47de28ae
MW
664.B union
665.IB C __vtu_ h
47de28ae
MW
666containing a member
667.IP
668.B struct
669.IB A __vt_ h
670.IB a ;
671.PP
672for each of
673.IR C 's
674superclasses
675.I A
676in the same chain,
677with
678.I C
679itself listed first.
680This is mostly an irrelevant detail,
681whose purpose is to defend against malicious compilers:
682pointers are always to one of the inner
683.B vt
684structures.
685It's important only because it's the outer
686.B vtu
687union which is exported by name.
688Specifically, for each chain of
689.IR C 's
690superclasses
691there is an external object
692.IP
693.B const union
694.IB A __vtu_ i
695.IB C __vtable_ i ;
696.PP
697where
698.I A
699and
700.I I
701are respectively the most and least specific classes in the chain.
702.PP
703The first member in the
704.B vt
705structure is the
706.I root class pointer
707.IP
708.B const
709.IR P
710.B *_class;
711.PP
712Among the superclasses of
713.I C
714there must be exactly one class
715.I O
716which itself has no direct superclasses;
717this is the
718.I root superclass
719of
720.IR C .
721(This is a rule enforced by the Sod translator.)
722The metaclass
723.I R
724of
9c4a4110 725.I O
47de28ae
MW
726is then the
727.I root metaclass
728of
729.IR C .
730The
731.B _class
732member points to the
733.B ichain
734structure of most specific superclass
735.I P
736of
737.I M
738in the same chain as
739.IR R .
740.PP
741This is followed by the
742.I base offset
743.IP
744.B size_t
745.B _base;
746.PP
747which is simply the offset of the
748.B ichain
749structure from the instance base.
750.PP
751The rest of the vtable structure is populated
752by walking the superclass chain containing
753.I C
754as follows.
755For each such superclass
756.IR B ,
757in increasing order of specificity,
758walk the class precedence list of
759.IR B ,
760again starting with its least-specific superclass.
761(This complex procedure guarantees that
762the vtable structure for a class is a prefix of
763the vtable structure for any of its subclasses in the same chain.)
764.PP
765So, let
766.I A
767be some superclass of
768.I C
769which has been encountered during this traversal.
770.hP \*o
771Let
772.I N
773be the metaclass of
774.IR A .
775Examine the superclass chains of
776.I N
777in order of decreasing specificity of their most-specific classes.
778Let
779.I J
780be the chain head of such a chain,
781and let
782.I Q
783be the most specific superclass of
784.I M
785in the same chain as
786.IR J .
787Then, if there is currently no class pointer of type
9c4a4110 788.IR Q ,
47de28ae
MW
789then add a member
790.RS
791.IP
792.B const
793.I Q
794.BI *_cls_ j ;
795.PP
796to the vtable
797pointing to the appropriate
798.B islots
799structure within
800.IR M 's
801class object.
802.RE
803.hP \*o
804Examine the superclass chains of
805.I A
806in order of decreasing specificity of their most-specific classes.
807Let
808.I I
809be the chain head of such a chain.
810If there is currently no member
811.BI _off_ i
812then add a member
813.RS
814.IP
815.B ptrdiff_t
816.BI _off_ i ;
817.PP
818to the vtable,
819containing the (signed) offset from the
820.B ichain
821structure of the chain headed by
822.I h
823to that of the chain headed by
824.I i
825within the instance's layout.
826.RE
827.hP \*o
828If class
829.I A
830defines any messages,
831and there is currently no member
9c4a4110 832.IR a ,
47de28ae
MW
833then add a member
834.RS
835.IP
836.B struct
837.IB C __vtmsgs_ a
838.IB a ;
839.PP
840to the vtable.
841See below.
842.RE
843.PP
844Finally, the
845.B vtmsgs
846structures contain pointers to the effective method entry functions
847for the messages defined by a superclass.
848There may be more than one method entry for a message,
849but all of the entry pointers for a message appear together,
850and entry pointers for separate messages appear
851in the order in which the messages are defined.
852If the receiver class has no applicable primary method for a message
853then it's usual for the method entry pointer to be null
854(though, as with a lot of things in Sod,
855extensions may do something different).
856.PP
857For a standard message which takes a fixed number of arguments,
858defined as
859.IP
860.I tr
861.IB m ( \c
862.I t1
863.IB a1 ,
864.RB ... ,
865.I tn
866.IB an );
867.PP
868there is always a `main' entry point,
869.IP
870.I tr
871.BI (* m )( \c
872.I C
873.BI * me ,
874.I t1
875.IB a1 ,
876.RB ... ,
877.I tn
878.IB an );
879.PP
880For a standard message which takes a variable number of arguments,
881defined as
882.IP
883.I tr
884.IB m ( \c
885.I t1
886.IB a1 ,
887.RB ... ,
888.I tn
889.IB an ,
890.B ...);
891.PP
43073476
MW
892or a standard message which takes keyword arguments,
893defined as
894.IP
895.I tr
896.IB m ( \c
897.I t1
898.IB a1 ,
899.RB ... ,
900.I tn
901.IB an ?\&
902.IR tn +1
903.IR kn +1
904.RB [ =
905.IR dn +1] \c
906.B ,
907.I tm
908.I km
909.RB [ =
910.IR dm ] \c
911);
912.PP
47de28ae
MW
913two entry points are defined:
914the usual `main' entry point
915which accepts a variable number of
916arguments,
917and a `valist' entry point
918which accepts an argument of type
919.B va_list
43073476
MW
920in place of the variable portion of the argument list
921or keywords.
47de28ae
MW
922.IP
923.I tr
924.BI (* m )( \c
925.I C
926.BI * me ,
927.I t1
928.IB a1 ,
929.RB ... ,
930.I tn
931.IB an ,
932.B ...);
933.br
934.I tr
935.BI (* m __v)( \c
936.I C
937.BI * me ,
938.I t1
939.IB a1 ,
940.RB ... ,
941.I tn
942.IB an ,
943.B va_list
944.IB sod__ap );
945.
946.SS Additional definitions
947In addition to the instance and vtable structures described above,
948the following definitions are made for each class
949.IR C .
950.PP
951For each message
952.I m
953directly defined by
954.I C
955there is a macro definition
956.IP
957.B #define
958.IB C _ m ( me ,
959.RB ... )
960.IB me ->_vt-> c . m ( me ,
961.RB ... )
962.PP
963which makes sending the message
964.I m
965to an instance of (any subclass of)
966.I C
967somewhat less ugly.
968If
969.I m
970takes a variable number of arguments,
43073476 971or keyword arguments,
47de28ae
MW
972the macro is more complicated
973and is only available in compilers advertising C99 support,
974but the effect is the same.
975For each variable-argument message,
976there is also an additional macro
977for calling the `valist' entry point.
978.IP
979.B #define
980.IB C _ m __v( me ,
981.RB ...,
982.IB sod__ap )
983.if !t \{\
984\e
985.br
986\h'4m'\c
987.\}
988.IB me ->_vt-> c . m __v( me ,
989.RB ...,
990.IB sod__ap )
991.PP
992For each proper superclass
993.I A
994of
995.IR C ,
996there is a macro defined
997.IP
998.I A
999.BI * C __CONV_ a ( C
1000.BI * _obj );
1001.PP
1002(named in
1003.IR "upper case" )
1004which converts a (static-type) pointer to
1005.I C
1006to a pointer to the same actual instance,
1007but statically typed as a pointer to
1008.IR A .
1009This is most useful when
1010.I A
1011is not in the same chain as
1012.I C
1013since in-chain upcasts are both trivial and rarely needed,
1014but the full set is defined for the sake of completeness.
1015.PP
1016Finally, the class object is defined as
1017.IP
1018.B extern const struct
1019.IB R __ilayout
1020.IB C __classobj;
1021.br
1022.B #define
1023.IB C __class
1024.BI (& C __classobj. j . r )
1025.PP
1026The exported symbol
1027.IB C __classobj
1028contains the entire class instance.
1029This is usually rather unwieldy.
1030The macro
1031.IB C __class
1032is usable as a pointer of type
1033.B const
1034.I R
1035.BR * ,
1036where
1037.I R
1038is the root metaclass of
1039.IR C ,
1040i.e., the metaclass of the least specific superclass of
1041.IR C ;
1042usually this is
1043.BR "const SodClass *" .
1044.
1045.\"--------------------------------------------------------------------------
1046.SH SEE ALSO
1047.BR sod (3).
1048.
1049.\"--------------------------------------------------------------------------
1050.SH AUTHOR
1051Mark Wooding, <mdw@distorted.org.uk>
1052.
1053.\"----- That's all, folks --------------------------------------------------