From: xchaos Date: Thu, 21 Aug 2008 09:54:26 +0000 (+0000) Subject: #3 lvalue forced in object method invocation macro X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=bd69f0f0801fc5f1ac360a45fb89051fb0c1aaf8;p=svn%2FCll1h%2F.git #3 lvalue forced in object method invocation macro git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@81 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- diff --git a/cll1.h b/cll1.h index 0ad5db9..2e27140 100644 --- a/cll1.h +++ b/cll1.h @@ -185,7 +185,7 @@ extern unsigned RANDOM_SEED; #define construct(TYPE,INTERFACE) TYPE _init_##TYPE(TYPE o,INTERFACE i) { o->__interface=i; return o; } TYPE __init__##TYPE #define get_obj(TYPE,INTERFACE,...) __init__##TYPE(_init_##TYPE(get_mem(TYPE),INTERFACE),__VA_ARGS__) #define get_obj_as(COMMUNITY,MEM,INTERFACE,...) (COMMUNITY)get_obj(MEM,INTERFACE,__VA_ARGS__) -#define _(METHOD,...) (((_ARG1(__VA_ARGS__,)) && (_ARG1(__VA_ARGS__,))->__interface->METHOD)?(*( (_ARG1(__VA_ARGS__,))->__interface->METHOD )) ((void *)__VA_ARGS__):0 ) +#define _(METHOD,...) ((((_ARG1(__VA_ARGS__,)) || /* will not compile if object is not Lvalue: */(_ARG1(__VA_ARGS__,)=NULL)) && (_ARG1(__VA_ARGS__,))->__interface->METHOD)?(*( (_ARG1(__VA_ARGS__,))->__interface->METHOD )) ((void *)__VA_ARGS__):0) #define __(METHOD,...) ( _ASSERT(ARG1(__VA_ARGS__,)), (*( __cll1_seekmethod(ARG1(__VA_ARGS__,),METHOD) )) ( __VA_ARGS__ ) ) #define call(OBJTYPE,METHOD,...) { int _N=0; OBJTYPE _OBJ; /* <-' */ while( (_OBJ=(OBJTYPE)_cll1_for_ptrs(_N++,__VA_ARGS__,NIL))!=(OBJTYPE)NIL ) _(_OBJ,METHOD); } #define def_community(TYPE,INTERFACE) def_obj(TYPE) { INTERFACE __interface; }; diff --git a/demos/objects/objects-wiki.c b/demos/objects/objects-wiki.c index 2fbab8f..8b6251a 100644 --- a/demos/objects/objects-wiki.c +++ b/demos/objects/objects-wiki.c @@ -70,6 +70,7 @@ program for_range(i, 0, 2) { - print(animal[i]->name, ":", _(talk,animal[i])); + print(animal[i]->name, ":", _(talk, animal[i])); } + }