From: Mark Wooding Date: Sun, 30 Aug 2015 09:58:38 +0000 (+0100) Subject: lib/sod.h, test/chimaera.sod: Promote `SOD_DECL' to the library header. X-Git-Tag: 0.2.0~37 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/267dd3e78997ba6f5a0801c0afab2148dd049f16 lib/sod.h, test/chimaera.sod: Promote `SOD_DECL' to the library header. It seems generally useful. --- diff --git a/lib/sod.h b/lib/sod.h index 594e343..919b927 100644 --- a/lib/sod.h +++ b/lib/sod.h @@ -168,6 +168,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@ --- * diff --git a/test/chimaera.sod b/test/chimaera.sod index d748bb5..cc72a47 100644 --- a/test/chimaera.sod +++ b/test/chimaera.sod @@ -77,10 +77,6 @@ static void provoke_serpent(Serpent *s) s->_vt->serpent.bite(s); } -#define SOD_DECL(cls_, var_) \ - struct cls_##__ilayout var_##__layout; \ - cls_ *var_ = cls_##__class->cls.init(&var_##__layout) - int main(void) { {