[Gambas-user] strange problem with NOT

Benoit Minisini gambas at ...1...
Mon Mar 21 18:02:33 CET 2005


On Friday 18 March 2005 19:51, Jean-Francois Perreault wrote:
> Hi,
>
> I found this "problem" with NOT , I'm pretty sure VB doesn't behave this
> way
>
> for this code
>
> DIM X as Integer
>
> x = 1
> PRINT "X is 1"
> IF x = 0 THEN PRINT "x = 0 returned TRUE"
> IF NOT x = 0 THEN PRINT "NOT x = 0 returned true"
> IF NOT (x = 0) THEN PRINT "NOT (x = 0) returned true"
>
> x = 0
> PRINT "X is 0"
> IF x = 0 THEN PRINT "x = 0 returned TRUE"
> IF NOT x = 0 THEN PRINT "NOT x = 0 returned true"
> IF NOT (x = 0) THEN PRINT "NOT (x = 0) returned true"
>
> if you run this you'll get the surprising output
>
> X is 1
> NOT (x = 0) returned true
> X is 0
> x = 0 returned true
>
>
> it's as if NOT was a function NOT() and not a logic keyword !
>
> I'm pretty sure vb would have turned both
>
> NOT x = 0 returned true
> NOT (x = 0) returned true
>
> (that is if VB had a PRINT function ;) )
> I don't have vb installed right now so I can't test , but that
> behavior sure puzzled me in the form of a bug in my program !!!
>
> ---
> Jean-Francois Perreault
>
>

The Not operator has a priority greater than comparison operators in Gambas.

You can see the priority of each operator in the 'gb_reserved_temp.h' file in 
the 'share' directory.

Should Gambas operators have exactly the same priority than in VB ? Anyway, 
you can use parenthesis to force the priority without fear - it does not slow 
the interpreter.

We can decide all together to change priorities if there are good reasons for 
that. The development version is done for that - breaking everything :-)

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list