cc: [email protected] [email protected]
Subject: Re: Re: [ast-users] Problems with (( !b ... )) and bools...
--------

On 25 July 2013 15:44, David Korn <[email protected]> wrote:
> cc: [email protected]
> Subject: Re: Problems with (( !b ... )) and bools...
> --------
>
> >> Hi!
> >> ----
> >> The following example prints the wrong boolean value with
> >> ast-ksh.2013-07-19 on SuSE 12.3/AMD64/64bit:
> >> -- snip --
> >> $ ./arch/linux.i386-64/bin/ksh -c 'bool b=true ; ((
> >> b=(!b)?(!false):(!true) )) ; printf "%s\n" "$b"'
> >> true
> >> -- snip --
> >>
> >> AFAIK it should print "false" ...
> >>
> >> ----
> >> Bye,
> >> Roland
> >>
> >
> > true and false are not constants so there is no meaning to true and
> > false unless you create varibles true and false and define them
> > as 1 and 0.
> >
> > bool is an enumeration contain the enumeration constants true and
> > false.  This is no different than
> >
> > enum Color=(red green blue yellow)
> 
> How can I access the integer value of a enum? Is integer i; ((
> i=Color.green )) valid?
> 
> > There is no meaning to !blue inside an arithmetic expression except
> > to do ! blue where blue is a variable.
> 
> David, I think you are wrong. First, assuming that ksh arithmetic
> expressions work like ANSI C arithmetic expressions a bool from
> stdbool.h is still of type bool if the negation (!) operator has been
> applied, i.e. the result of !b is still of type bool.
> Second, as the result of !b is of type bool, shouldn't be b=!true a
> valid expression?
> 
> > The only operators that recognize enumeriation constants are
> >         == != and =
> > when the left hand size is an enumeration variable.
> >
> > My patch allowed
> >         enum_var = expr?var1:var2
> > to recognize var1 and var2 as possible enumeration constants,
> > but it does not recognize !var1.
> 
> Why are enumerations handled special? Can the ksh arithmetic
> expression engine not just take their integer value?
> 
> Wendy
> 

In C, with <stdbool.h> true and false are constants.  In ksh, true and
false are valid variable names.

bool is an enumeration consisting of enumeration constants true and false.
In C you can't do
        int false=5;
In shell you can do
        integer false=5.


The shell recognizes enumeriation constants are with operators
        == != and =
only.

If I make it compatible with C, then any script that uses true and false
as variables would break and violate the C standard.

David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to