added check for lvalue to coalesce() macro (to prevent double evaluation of expressio...
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Thu, 21 Aug 2008 11:44:42 +0000 (11:44 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Thu, 21 Aug 2008 11:44:42 +0000 (11:44 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@82 4bb87942-c103-4e5a-b51c-0ebff58f8515

cll1.h
demos/advanced-hello-world.c

diff --git a/cll1.h b/cll1.h
index 2e27140dbd2e76f30bd3d47f05d999d6fbb9d475..c49fa3c2a98997bb8a92bc28c0435d36310a0c6f 100644 (file)
--- a/cll1.h
+++ b/cll1.h
@@ -88,7 +88,8 @@ extern  unsigned RANDOM_SEED;
 #define PI 3.141592654
 #define WEIRDINT (1<<(sizeof(int)*8-1))
 #define btoa(EXPR) ((EXPR)?"TRUE":"FALSE")
-#define coalesce(VAR,EXPR) (VAR?VAR:(EXPR))
+#define coalesce(VAR,EXPR) (VAR?VAR:(VAR=0,(EXPR)))
+#define coalesce_str(VAR,EXPR) (VAR && *VAR?VAR:((VAR=NULL),(EXPR)))
 /* .----------------------------------------------------------------------.
   /  4. C<<1 data declaration and allocation, updated 2008-01-31 xCh.
  '----------------------------------------------------------------------- */
@@ -185,7 +186,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__,)) || /* 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,...) ((((_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; };
index a5475ba5efc3e313d4cf3b51913c0d3210766bf8..124788a5f180d5cb9a86f637898fe31d91a900a3 100644 (file)
@@ -7,11 +7,16 @@ program
  print("* print()");
  print("Hello","world","!");
  print("* NIL");
- print("We can print",NULL,"safely.");
+ print("We can print", NULL, "safely.");
  NIL="(hic sunt crocodiles)";
- print("We can print",NULL,"safely.");
- print("* coalesce():"); 
- print("We can",coalesce("print","everything"),"almost",coalesce(NULL,"anything"),"safely."); 
+ print("We can print", NULL, "safely.");
+
+ {
+  str p = "print", a = NULL;
+  print("* coalesce():"); 
+  print("We can", coalesce(p, "everything"), "almost", coalesce(a, "anything"), "safely."); 
+ }
+
  echo("Surprisingly ->",NIL," (you can't see this)");
  print("<- nothing special here.");
  print("* OFS");
This page took 0.154036 seconds and 4 git commands to generate.