You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2003/04/19 21:35:47 UTC

[apreq-2] conditionals

For apreq-2, VC++ on Win32 (and perhaps also some other 
compilers?) doesn't like statements like
  (some_condition) ? do_something : do_something_else;
This diff (unfortunately :)

=========================================================
Index: apreq_tables.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq_tables.c,v
retrieving revision 1.13
diff -u -r1.13 apreq_tables.c
--- apreq_tables.c	19 Apr 2003 16:21:31 -0000	1.13
+++ apreq_tables.c	19 Apr 2003 19:42:18 -0000
@@ -176,7 +176,12 @@
     if (pivot[o].tree[!direction] >= 0)
         pivot[o].tree[!direction][o].tree[PARENT] = pivot;
 
-    (parent >= 0) ? parent[o].tree[LR(pivot)] : *root = child;
+    if (parent >= 0) {
+        parent[o].tree[LR(pivot)];
+    }
+    else {
+        *root = child;
+    }
 
     child[o].tree[PARENT]      = parent;
     child[o].tree[direction]   = pivot;
@@ -256,7 +261,12 @@
             if (x[o].tree[RIGHT] >= 0)
                 x[o].tree[RIGHT][o].tree[PARENT] = idx;
 
-            (parent >= 0) ? parent[o].tree[LR(x)] : *root = idx;
+            if (parent >= 0) {
+                parent[o].tree[LR(x)];
+            }
+            else {
+                *root = idx;
+            }
 
             elt->tree[PARENT] = parent;
             elt->tree[RIGHT]  = x[o].tree[RIGHT];
@@ -333,7 +343,12 @@
         y[o].tree[RIGHT]  = idx[o].tree[RIGHT];
         y[o].color        = idx[o].color;
 
-        (x >= 0) ? x[o].tree[LR(idx)] : *root = y;
+        if (x >= 0) {
+            x[o].tree[LR(idx)];
+        }
+        else {
+            *root = y;
+        }
 
         idx[o].tree[PARENT] = -1;
         idx[o].tree[LEFT]   = -1;
@@ -356,16 +371,24 @@
     /* remove y from the parent chain */
     x[o].tree[PARENT] = y[o].tree[PARENT];
 
-    (y[o].tree[PARENT] >= 0) ?
-        y[o].tree[PARENT][o].tree[LR(y)] : *root = x;
+    if (y[o].tree[PARENT] >= 0) {
+        y[o].tree[PARENT][o].tree[LR(y)];
+    }
+    else {
+        *root = x;
+    }
 
     if (y != idx) {     /* swap y[o] with idx[o] */
         y[o].tree[LEFT] = idx[o].tree[LEFT];
         y[o].tree[RIGHT] = idx[o].tree[RIGHT];
         y[o].tree[PARENT] = idx[o].tree[PARENT];
         
-        (y[o].tree[PARENT] >= 0) ?
-            y[o].tree[PARENT][o].tree[LR(y)] : *root = y;
+        if (y[o].tree[PARENT] >= 0) {
+            y[o].tree[PARENT][o].tree[LR(y)];
+        }
+        else {
+            *root = y;
+        }
 
         idx[o].tree[LEFT] = -1;
         idx[o].tree[RIGHT] = -1;
================================================================
allows apreq_tables.c to compile.

-- 
best regards,
randy


Re: [apreq-2] conditionals

Posted by "David N. Welton" <da...@dedasys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:

> Cool, but I'd rather see that written this way
> 
>   if (a > 0)
>       c = 3;
>   else
>       d = 3;

+1 - it increases readability.  I don't like using the ternary
operator where it too makes the code easier to read, and there aren't
that many cases where that is true.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

Re: [apreq-2] cookie_bake vs bake_cookie?

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

> For apreq-2, in src/, apreq_cookie.h declares
> apreq_cookie_bake() and apreq_cookie_bake2(), whereas
> apreq_cookie.c has apreq_bake_cookie() and apreq_bake2_cookie().
> This diff:
> ===========================================================
> Index: apreq_cookie.c
> ===================================================================
> RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.c,v
> retrieving revision 1.14
> diff -u -r1.14 apreq_cookie.c
> --- apreq_cookie.c	7 Jun 2003 20:07:41 -0000	1.14
> +++ apreq_cookie.c	9 Jun 2003 06:00:43 -0000
> @@ -478,7 +478,7 @@
>          return NULL;
>  }
> 
> -APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c,
> +APREQ_DECLARE(apr_status_t) apreq_cookie_bake(const apreq_cookie_t *c,
>                                                void *env)
>  {
>      char *s = apreq_cookie_as_string(apreq_env_pool(env),c);
> @@ -493,7 +493,7 @@
>      return apreq_env_set_cookie(env, s);
>  }
> 
> -APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c,
> +APREQ_DECLARE(apr_status_t) apreq_cookie_bake2(const apreq_cookie_t *c,
>                                                 void *env)
>  {
>      char *s = apreq_cookie_as_string(apreq_env_pool(env),c);
> ====================================================================

OOPS.  It should be apreq_cookie_bake* to better match
the Perl api.  

Thanks Randy, applied.

-- 
Joe Schaefer


[apreq-2] cookie_bake vs bake_cookie?

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
For apreq-2, in src/, apreq_cookie.h declares
apreq_cookie_bake() and apreq_cookie_bake2(), whereas
apreq_cookie.c has apreq_bake_cookie() and apreq_bake2_cookie().
This diff:
===========================================================
Index: apreq_cookie.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.c,v
retrieving revision 1.14
diff -u -r1.14 apreq_cookie.c
--- apreq_cookie.c	7 Jun 2003 20:07:41 -0000	1.14
+++ apreq_cookie.c	9 Jun 2003 06:00:43 -0000
@@ -478,7 +478,7 @@
         return NULL;
 }

-APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c,
+APREQ_DECLARE(apr_status_t) apreq_cookie_bake(const apreq_cookie_t *c,
                                               void *env)
 {
     char *s = apreq_cookie_as_string(apreq_env_pool(env),c);
@@ -493,7 +493,7 @@
     return apreq_env_set_cookie(env, s);
 }

-APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c,
+APREQ_DECLARE(apr_status_t) apreq_cookie_bake2(const apreq_cookie_t *c,
                                                void *env)
 {
     char *s = apreq_cookie_as_string(apreq_env_pool(env),c);
====================================================================
changes the definitions in apreq_cookie.c to agree with the
declarations in apreq_cookie.h.

-- 
best regards,
randy kobes

Re: [apreq-2] conditionals

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

> On 19 Apr 2003, Joe Schaefer wrote:
> 
> [ .. ]
> > Actually, all the suggestions you made today are fine
> > with me except for the strcasecmp one.  I put the t->cmp
> > (mis)feature in way before the tables were implemented, and 
> > now I'd rather see it pulled out entirely.  IMO we should 
> > just use strcasecmp whereever t->cmp is used in the 
> > apreq_tables.c source. 
> 
> Something like the following?

[...patch..]

Yup, exactly what I had in mind.  Thanks alot, Randy!

-- 
Joe Schaefer

Re: [apreq-2] conditionals

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On 19 Apr 2003, Joe Schaefer wrote:

[ .. ]
> Actually, all the suggestions you made today are fine
> with me except for the strcasecmp one.  I put the t->cmp
> (mis)feature in way before the tables were implemented, and 
> now I'd rather see it pulled out entirely.  IMO we should 
> just use strcasecmp whereever t->cmp is used in the 
> apreq_tables.c source. 

Something like the following?

==============================================================
Index: apreq_tables.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq_tables.c,v
retrieving revision 1.14
diff -u -r1.14 apreq_tables.c
--- apreq_tables.c	20 Apr 2003 03:37:45 -0000	1.14
+++ apreq_tables.c	20 Apr 2003 04:16:09 -0000
@@ -112,10 +112,6 @@
 #define UNLOCK_TREE(t,n)
 #define TREE_IS_LOCKED(t,n)
 
-
-/* This may someday become public, but has hash+tree harmony embedded. */
-typedef int (apreq_table_cmp_t)(const char *, const char *);
-
 #define TF_MERGE     1
 #define TF_BALANCE   2
 #define TF_LOCK      4
@@ -125,8 +121,6 @@
     apr_array_header_t   a;
     int                  ghosts;
 
-    apreq_table_cmp_t   *cmp;
-
     apreq_value_copy_t  *copy;
     apreq_value_merge_t *merge;
 
@@ -188,8 +182,7 @@
 }
 
 
-static APR_INLINE int search(apreq_table_cmp_t *cmp,
-                             apreq_table_entry_t *o, 
+static APR_INLINE int search(apreq_table_entry_t *o, 
                              int *elt,
                              const char *key) 
 {
@@ -197,7 +190,7 @@
     if ( idx < 0)
         return 0;
     while (1) {
-        int direction = (*cmp)(key,idx[o].key);
+        int direction = strcasecmp(key,idx[o].key);
 
         if (direction < 0 && idx[o].tree[LEFT] >= 0)
             idx = idx[o].tree[LEFT];
@@ -218,13 +211,12 @@
 #define TREE_POP       1
 #define TREE_DROP      2
 
-static int insert(apreq_table_cmp_t *cmp,
-                  apreq_table_entry_t *o, int *root, int x,
+static int insert(apreq_table_entry_t *o, int *root, int x,
                   apreq_table_entry_t *elt,
                   unsigned flags )
 {
     int idx = elt - o;
-    int s = search(cmp, o, &x, elt->key);
+    int s = search(o, &x, elt->key);
 
     if (s == 0) { /* found */
         if (x < 0) { /* empty tree */
@@ -436,8 +428,7 @@
     x[o].color = BLACK;
 }
 
-static int combine(apreq_table_cmp_t *cmp,
-                   apreq_table_entry_t *o, int a, 
+static int combine(apreq_table_entry_t *o, int a, 
                    int b, const int n)
 {
     int left, right, next;
@@ -461,23 +452,23 @@
             a[o].tree[PARENT] = -1;
         }
 
-        if (insert(cmp,o,&a,a,b+o, TREE_PUSH) < 0)
+        if (insert(o,&a,a,b+o, TREE_PUSH) < 0)
             rv = b;
 
         if (b[o].tree[PARENT] >= 0)
             PROMOTE(o,&a,b);
 
         b[o].tree[PARENT] = parent;
-        b[o].tree[LEFT]  = combine(cmp, o, b[o].tree[LEFT],  left,  n);
-        b[o].tree[RIGHT] = combine(cmp, o, b[o].tree[RIGHT], right, n);
+        b[o].tree[LEFT]  = combine(o, b[o].tree[LEFT],  left,  n);
+        b[o].tree[RIGHT] = combine(o, b[o].tree[RIGHT], right, n);
 
         return rv;
     }
     else {
         if (b[o].tree[PARENT] >= 0)
             b[o].tree[PARENT] += n;
-        b[o].tree[LEFT]  = combine(cmp, o, -1,  left, n);
-        b[o].tree[RIGHT] = combine(cmp, o, -1, right, n);
+        b[o].tree[LEFT]  = combine(o, -1,  left, n);
+        b[o].tree[RIGHT] = combine(o, -1, right, n);
 
         return b;
     }
@@ -567,7 +558,6 @@
     /* XXX: is memset(*,-1,*) portable ??? */
     memset(t->root, -1, TABLE_HASH_SIZE * sizeof(int));
 
-    t->cmp    = strcasecmp;
     t->merge  = apreq_merge_values;
     t->copy   = apreq_copy_value;
     t->flags  = 0;
@@ -596,7 +586,6 @@
     memcpy(new->root, t->root, TABLE_HASH_SIZE * sizeof(int));
     new->merge = t->merge;
     new->copy = t->copy;
-    new->cmp = t->cmp;
     new->flags=t->flags;
     return new;
 }
@@ -688,7 +677,7 @@
 
         memset(t->root,-1,TABLE_HASH_SIZE * sizeof(int));
         for (idx = 0; idx < t->a.nelts; ++idx)
-            insert(t->cmp, o, &t->root[TABLE_HASH(idx[o].key)], -1, &idx[o], 
+            insert(o, &t->root[TABLE_HASH(idx[o].key)], -1, &idx[o], 
                    TF_BALANCE | TREE_PUSH);
 
         t->flags |= TF_BALANCE;
@@ -842,7 +831,7 @@
     int idx = t->root[TABLE_HASH(key)];
     apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
 
-    if ( idx < 0 || search(t->cmp,o,&idx,key) )
+    if ( idx < 0 || search(o,&idx,key) )
 	return NULL;
 
     return v2c(idx[o].val);
@@ -855,7 +844,7 @@
     int idx = *root;
     apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
 
-    if ( idx < 0 || search(t->cmp,o,&idx,key) )
+    if ( idx < 0 || search(o,&idx,key) )
 	return NULL;
 
     if (idx != *root) {
@@ -883,7 +872,7 @@
     }
     else {
         idx = t->root[TABLE_HASH(key)];
-        if ( idx>=0 && search(t->cmp,o,&idx,key) == 0 )
+        if ( idx>=0 && search(o,&idx,key) == 0 )
            for ( ; idx>=0; idx = idx[o].tree[NEXT] )
                 *(const apreq_value_t **)apr_array_push(a) = idx[o].val;
     }
@@ -908,7 +897,7 @@
     }
 #endif
 
-    if (idx >= 0 && search(t->cmp,o,&idx,key) == 0) {
+    if (idx >= 0 && search(o,&idx,key) == 0) {
         int n;
         idx[o].val = val;
 
@@ -922,7 +911,7 @@
         e->key = key;
         e->val = val;
         e->tree[NEXT] = -1;
-        insert(t->cmp,(apreq_table_entry_t *)t->a.elts,
+        insert((apreq_table_entry_t *)t->a.elts,
                &t->root[TABLE_HASH(key)],idx,e,TREE_PUSH);
     }
 }
@@ -932,7 +921,7 @@
     int idx = t->root[TABLE_HASH(key)];
     apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
 
-    if (idx >= 0 && search(t->cmp,o,&idx,key) == 0) {
+    if (idx >= 0 && search(o,&idx,key) == 0) {
         int n;
 
         LOCK_TABLE(t);
@@ -959,7 +948,7 @@
     apreq_table_entry_t *e;
 
 
-    if (idx >= 0 && search(t->cmp,o,&idx,val->name) == 0) {
+    if (idx >= 0 && search(o,&idx,val->name) == 0) {
         int n;
         apreq_value_t *a[APREQ_NELTS];
         apr_array_header_t arr = { t->a.pool, sizeof(apreq_value_t *), 0,
@@ -998,7 +987,7 @@
         e->key = val->name;
         e->val = val;
         e->tree[NEXT] = -1;
-        insert(t->cmp,(apreq_table_entry_t *)t->a.elts,
+        insert((apreq_table_entry_t *)t->a.elts,
                &t->root[TABLE_HASH(key)],idx,e,TREE_PUSH);
     }
     return val->status;
@@ -1030,7 +1019,7 @@
         elt->key = val->name;
         elt->val = val;
         elt->tree[NEXT] = -1;
-        insert(t->cmp, o, root, *root, elt, TREE_PUSH);
+        insert(o, root, *root, elt, TREE_PUSH);
         return APR_SUCCESS;
     }
 
@@ -1084,14 +1073,14 @@
             else if ( idx[o].tree[PARENT] >= 0 || 
                       s->root[hash] == idx-n ) 
             {
-                insert(t->cmp, o, &t->root[hash], t->root[hash], idx+o, 
+                insert(o, &t->root[hash], t->root[hash], idx+o, 
                        TREE_PUSH | TF_BALANCE);
             }
         }
     }
     else {
         for (idx = 0; idx < TABLE_HASH_SIZE; ++idx)
-            t->root[idx] = combine(t->cmp, o,t->root[idx],s->root[idx],n);
+            t->root[idx] = combine(o,t->root[idx],s->root[idx],n);
     }
 
     UNLOCK_TABLE(t);
@@ -1120,13 +1109,9 @@
     }
 #endif
 
-    if (overlay->cmp != base->cmp)
-        return NULL;
-
     t->a.pool = p;
     t->a.elt_size = sizeof(apreq_table_entry_t);
     t->copy = overlay->copy;
-    t->cmp = overlay->cmp;
     t->merge = overlay->merge;
     t->flags = overlay->flags & base->flags;
     t->ghosts = overlay->ghosts;
@@ -1164,9 +1149,6 @@
     if (m + n == 0)
         return APR_SUCCESS;
 
-    if ( a->cmp != b->cmp)
-        return APR_EMISMATCH;
-
     /* copy (extend) a using b's pool */
     if (a->a.pool != p) {
         make_array_core(&a->a, p, m+n, sizeof(apreq_table_entry_t), 0);
@@ -1360,7 +1342,7 @@
         int rv = 1, idx;
         if (argp) {     /* Scan for entries that match the next key */
             idx = t->root[TABLE_HASH(argp)];
-            if ( search(t->cmp,o,&idx,argp) == 0 )
+            if ( search(o,&idx,argp) == 0 )
                 while (idx >= 0) {
                     rv = (*comp) (rec, idx[o].key, v2c(idx[o].val));
                     idx = idx[o].tree[NEXT];
======================================================================

-- 
best regards,
randy


Re: [apreq-2] apreq.c warning

Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
> 
> [...]
> 
> 
>>Or, alternatively use:
>>
>>-  APREQ_DECLARE(long) apreq_atol(const char *s)
>>+  APREQ_DECLARE(apr_int64_t) apreq_atol(const char *s)
>>
>>it's probably better to stick to apr types, rather than convert back
>>and force. 
> 
> 
> OOPS- I already incorporated Randy's patch into the latest commit.
> I do agree that the apr_int64_t return type would be better here.
> 
> 
>>Of course this will require to adjust the types in the callers of this
>>function... 
> 
> 
> Can anyone suggest some better names for apreq_atoi and apreq_atol?
> They're identical functions except for their trailing character
> interpretations (file sizes vs dates).

it seems that it's the easiest to use the real return type in the name
I'd go for 'apreq_a2int64', but 'apreq_atoint64' is probably closer to atoi

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [apreq-2] apreq.c warning

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:

[...]

> Or, alternatively use:
> 
> -  APREQ_DECLARE(long) apreq_atol(const char *s)
> +  APREQ_DECLARE(apr_int64_t) apreq_atol(const char *s)
> 
> it's probably better to stick to apr types, rather than convert back
> and force. 

OOPS- I already incorporated Randy's patch into the latest commit.
I do agree that the apr_int64_t return type would be better here.

> Of course this will require to adjust the types in the callers of this
> function... 

Can anyone suggest some better names for apreq_atoi and apreq_atol?
They're identical functions except for their trailing character
interpretations (file sizes vs dates).

-- 
Joe Schaefer

Re: [apreq-2] apreq.c warning

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> The following diff:
> 
> ===================================================
> Index: apreq.c
> ===================================================================
> RCS file: /home/cvspublic/httpd-apreq-2/src/apreq.c,v
> retrieving revision 1.12
> diff -u -r1.12 apreq.c
> --- apreq.c	19 Apr 2003 09:42:08 -0000	1.12
> +++ apreq.c	20 Apr 2003 04:02:32 -0000
> @@ -166,11 +166,11 @@
>  
>  APREQ_DECLARE(long) apreq_atol(const char *s) 
>  {
> -    apr_int64_t n = 0;
> +    long n = 0;
>      char *p;
>      if (s == NULL)
>          return 0;
> -    n = apr_strtoi64(s, &p, 0); /* XXX: what about overflow? */
> +    n = (long) apr_strtoi64(s, &p, 0); /* XXX: what about overflow? */
>  
>      if (p == NULL)
>          return n;
> ===============================================================
> avoids warnings about a conversion from __int64 to long with 
> VC++ on Win32.

Or, alternatively use:

-  APREQ_DECLARE(long) apreq_atol(const char *s)
+  APREQ_DECLARE(apr_int64_t) apreq_atol(const char *s)

it's probably better to stick to apr types, rather than convert back and force.

Of course this will require to adjust the types in the callers of this function...

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


[apreq-2] apreq.c warning

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
The following diff:

===================================================
Index: apreq.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.12
diff -u -r1.12 apreq.c
--- apreq.c	19 Apr 2003 09:42:08 -0000	1.12
+++ apreq.c	20 Apr 2003 04:02:32 -0000
@@ -166,11 +166,11 @@
 
 APREQ_DECLARE(long) apreq_atol(const char *s) 
 {
-    apr_int64_t n = 0;
+    long n = 0;
     char *p;
     if (s == NULL)
         return 0;
-    n = apr_strtoi64(s, &p, 0); /* XXX: what about overflow? */
+    n = (long) apr_strtoi64(s, &p, 0); /* XXX: what about overflow? */
 
     if (p == NULL)
         return n;
===============================================================
avoids warnings about a conversion from __int64 to long with 
VC++ on Win32.

-- 
best regards,
randy


Re: [apreq-2] conditionals

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

[...]

> Ah - thanks for pointing that out. The error I'm getting with
> something like
>     (a > 0) ? c : d = 3;
> or
>     (a > 0 ? c : d) = 3;
> is
>    '=' : left operand must be l-value
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^

OOPS.  My mistake :-(

> What does work is 
>     (a > 0) ? (c=3) : (d=3);

Cool, but I'd rather see that written this way

  if (a > 0)
      c = 3;
  else
      d = 3;


I'd rather convert the bogus ?: lines to that format.
Randy, if you agree that this is better, please make
the commit.

Actually, all the suggestions you made today are fine
with me except for the strcasecmp one.  I put the t->cmp
(mis)feature in way before the tables were implemented, and 
now I'd rather see it pulled out entirely.  IMO we should 
just use strcasecmp whereever t->cmp is used in the 
apreq_tables.c source. 

-- 
Joe Schaefer

Re: [apreq-2] conditionals

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On 19 Apr 2003, Joe Schaefer wrote:

> Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:
> [...]
> 
> > -    (parent >= 0) ? parent[o].tree[LR(pivot)] : *root = child;
> > +    (parent >= 0) ? parent[o].tree[LR(pivot)] : (*root = child);
> 
> Those aren't equivalent.  The first one uses ?: to select the 
> lvalue - IOW it's doing this
> 
>   ( parent >= 0 ? parent[o].tree[LR(pivot)] : *root ) = child;
> 
> or at least it should be, since that's what I want to have 
> happen here.

Ah - thanks for pointing that out. The error I'm getting with
something like
    (a > 0) ? c : d = 3;
or
    (a > 0 ? c : d) = 3;
is
   '=' : left operand must be l-value
What does work is 
    (a > 0) ? (c=3) : (d=3);


-- 
best regards,
randy kobes


Re: [apreq-2] conditionals

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

[...]

> -    (parent >= 0) ? parent[o].tree[LR(pivot)] : *root = child;
> +    (parent >= 0) ? parent[o].tree[LR(pivot)] : (*root = child);

Those aren't equivalent.  The first one uses ?: to select the 
lvalue - IOW it's doing this

  ( parent >= 0 ? parent[o].tree[LR(pivot)] : *root ) = child;


or at least it should be, since that's what I want to have 
happen here.

-- 
Joe Schaefer

Re: [apreq-2] conditionals

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Sat, 19 Apr 2003, Randy Kobes wrote:

> For apreq-2, VC++ on Win32 (and perhaps also some other 
> compilers?) doesn't like statements like
>   (some_condition) ? do_something : do_something_else;
> This diff (unfortunately :)
[ .. ]

Bill pointed out a better solution:
=========================================================
Index: apreq_tables.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq_tables.c,v
retrieving revision 1.13
diff -u -r1.13 apreq_tables.c
--- apreq_tables.c	19 Apr 2003 16:21:31 -0000	1.13
+++ apreq_tables.c	19 Apr 2003 20:54:35 -0000
@@ -176,7 +176,7 @@
     if (pivot[o].tree[!direction] >= 0)
         pivot[o].tree[!direction][o].tree[PARENT] = pivot;
 
-    (parent >= 0) ? parent[o].tree[LR(pivot)] : *root = child;
+    (parent >= 0) ? parent[o].tree[LR(pivot)] : (*root = child);
 
     child[o].tree[PARENT]      = parent;
     child[o].tree[direction]   = pivot;
@@ -256,7 +256,7 @@
             if (x[o].tree[RIGHT] >= 0)
                 x[o].tree[RIGHT][o].tree[PARENT] = idx;
 
-            (parent >= 0) ? parent[o].tree[LR(x)] : *root = idx;
+            (parent >= 0) ? parent[o].tree[LR(x)] : (*root = idx);
 
             elt->tree[PARENT] = parent;
             elt->tree[RIGHT]  = x[o].tree[RIGHT];
@@ -333,7 +333,7 @@
         y[o].tree[RIGHT]  = idx[o].tree[RIGHT];
         y[o].color        = idx[o].color;
 
-        (x >= 0) ? x[o].tree[LR(idx)] : *root = y;
+        (x >= 0) ? x[o].tree[LR(idx)] : (*root = y);
 
         idx[o].tree[PARENT] = -1;
         idx[o].tree[LEFT]   = -1;
@@ -357,7 +357,7 @@
     x[o].tree[PARENT] = y[o].tree[PARENT];
 
     (y[o].tree[PARENT] >= 0) ?
-        y[o].tree[PARENT][o].tree[LR(y)] : *root = x;
+        y[o].tree[PARENT][o].tree[LR(y)] : (*root = x);
 
     if (y != idx) {     /* swap y[o] with idx[o] */
         y[o].tree[LEFT] = idx[o].tree[LEFT];
@@ -365,7 +365,7 @@
         y[o].tree[PARENT] = idx[o].tree[PARENT];
         
         (y[o].tree[PARENT] >= 0) ?
-            y[o].tree[PARENT][o].tree[LR(y)] : *root = y;
+            y[o].tree[PARENT][o].tree[LR(y)] : (*root = y);
 
         idx[o].tree[LEFT] = -1;
         idx[o].tree[RIGHT] = -1;
================================================================

-- 
best regards,
randy