X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/7d21069e791a4d164c1eb1fc4f1ae661fe08ffbe..d83a91c663ced211bb7e4509f800859c3fa086e9:/lib/sod.h diff --git a/lib/sod.h b/lib/sod.h index 594e343..8270895 100644 --- a/lib/sod.h +++ b/lib/sod.h @@ -53,7 +53,7 @@ struct sod_vtable { * these. */ struct sod_instance { - struct sod_vtable *_vt; /* Pointer to (chain's) vtable */ + const struct sod_vtable *_vt; /* Pointer to (chain's) vtable */ }; /* Information about a particular chain of superclasses. In each class, @@ -124,6 +124,18 @@ struct sod_chain { ((struct cls##__ilayout *) \ ((char *)(obj) - offsetof(struct cls##__ilayout, chead))) +/* --- @SOD__CAR@ --- * + * + * Arguments: @...@ = a nonempty list of arguments + * + * Returns: The first argument only. + */ + +#if __STDC_VERSION__ >= 199901 +# define SOD__CAR(...) SOD__CARx(__VA_LIST__, _) +# define SOD__CARx(a, ...) a +#endif + /*----- Utility macros ----------------------------------------------------*/ /* --- @SOD_CLASSOF@ --- * @@ -168,6 +180,19 @@ struct sod_chain { #define SOD_CONVERT(cls, obj) ((cls *)sod_convert(cls##__class, (obj))) +/* --- @SOD_DECL@ --- * + * + * Arguments: @cls_@ = a class type name + * @var_@ = a variable name + * + * Use: Declare @var_@ as a pointer to an initialized instance of + * @cls_@ with automatic lifetime. + */ + +#define SOD_DECL(cls_, var_) \ + struct cls_##__ilayout var_##__layout; \ + cls_ *var_ = cls_##__class->cls.init(&var_##__layout) + /*----- Functions provided ------------------------------------------------*/ /* --- @sod_subclassp@ --- *