[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: boolean issue with serf

From: Michae Sinz <Michael.Sinz_at_sinz.org>
Date: Thu, 16 Apr 2009 15:07:42 -0700

On Thu, Apr 16, 2009 at 1:36 PM, Greg Stein <gstein_at_gmail.com> wrote:

> On Thu, Apr 16, 2009 at 21:46, Stefan Küng <tortoisesvn_at_gmail.com> wrote:
> > C. Michael Pilato wrote:
> [...]
> > Hmm - according to wikipedia:
> > http://en.wikipedia.org/wiki/Boolean_datatype
> >
> > "However, problems arise from the fact that any non-zero value
> > represents true in C, while the value TRUE is represented by a specific
> > value. So while in other languages, if (foo == TRUE) ... is merely
> > redundant, in C, it is actually incorrect code."
>
> svn_boolean_t is defined as one of {TRUE, FALSE}.
>
> Pass one of those values. Wikipedia does not define our svn_boolean_t.

I agree that they don't define the svn_boolean_t but show me where the
compiler will respect that or enforce that?

Both at the user code path and in the actually evaluation of operations into
a boolean.

There are cases in code, depending on the compiler and optimizer, where in C
code the compiler itself will not force the value to be 0 or 1. In fact, a
common optimization trick has been used to let whatever non-zero pass
through or even use the non-zero to make -1 (all bits on in whatever word
size you expect). (Albeit these were highly optimizing embedded C compilers
- it has been years since I have looked at C code generation and
optimization paths and in other languages there is an actual boolean type
that can only have two values and thus the behavior of the code is more
strictly defined.)

PS - on CPU architectures there are instructions that expand the CPU
condition codes into a boolean value in a register such that no branching is
needed at all to store the result of a boolean operation/test. In at least
two of the cases these expand to -1 or 0 (all bits on or all bits off). I
would expect that those platforms would end up having a natural boolean
behavior of -1. This would make it impossible to correctly do:

       svn_boolean_t flag = (x > y);

and expect flag to contain either TRUE or FALSE (it may contain another
value).

Thus the code would have to be written:

       svn_boolean_t flag = (x > y) ? TRUE : FALSE;

which looks a bit redundant (and will be more code as the compiler will have
to do a test-branch-store or test-failbranch-store-branch to store the
correct value into flag or a register representing flag. With enough
optimization smarts it may be able to figure out that you could do
test-negate-store to get that to work out...

-- 
Michael Sinz               Technology and Engineering Director/Consultant
"Starting Startups"                          mailto:Michael.Sinz_at_sinz.org
My place on the web                      http://www.sinz.org/Michael.Sinz
------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1755763
Received on 2009-04-17 00:08:02 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.