IonicWind Software

IWBasic => General Questions => Topic started by: billhsln on January 13, 2007, 10:45:38 PM

Title: IBasic Pro stuff I can't find in EBasic Doc, so is it still valid?
Post by: billhsln on January 13, 2007, 10:45:38 PM
I have statements in my Old IBasic Pro code that I can not seem to find in the EBasic doc file and would like to make sure that they are still valid and will work the way I expect.

They are:

if (x=2) & (y=3) | (z=5)  ... does & equate to an 'AND' and | equates to 'OR'?

Also, I was able to do:

v1 += v2, which I expected to take the value in v2 and add 1 to it and store it in v1.  I don't see any of the += or -= commands, do they work?

Thanks,
Bill

Note:  I do not say that they don't compile, I just want to make sure they work the way I expect them to...
Title: Re: IBasic Pro stuff I can't find in EBasic Doc, so is it still valid?
Post by: Ionic Wind Support Team on January 13, 2007, 10:52:22 PM
They are in the docs.  See Language->Operators.  Same place they were in the IBasic Pro docs.

Title: Re: IBasic Pro stuff I can't find in EBasic Doc, so is it still valid?
Post by: mrainey on January 14, 2007, 06:13:47 AM
Quotev1 += v2, which I expected to take the value in v2 and add 1 to it and store it in v1.

Don't you mean, change the value in v1 by adding the value in v2 to it? 

The same as saying  v1 = v1 + v2
Title: Re: IBasic Pro stuff I can't find in EBasic Doc, so is it still valid?
Post by: billhsln on January 14, 2007, 08:00:34 AM
Thanks Paul and MRainey...I tried to find the info in the help file using search.  Found it exactly where you said.  And you are right v1 += v2 is v1 = v1 + v2...I get confused occasionally, I wrote that code a while back.

The AND and OR was in using it in a IF conditional, not in bitwise format, so maybe that is not 100% of the info I need.

My question on the AND and OR is, if:

IF (x=1) & (y=2) THEN z=4

is the same as:

IF (x=1) AND (y=2) THEN z=4

Thanks,
Bill
Title: Re: IBasic Pro stuff I can't find in EBasic Doc, so is it still valid?
Post by: Ionic Wind Support Team on January 14, 2007, 08:24:41 AM
No. Although the results are the same in this case.  Even in IBasic & and | were bitwise, however it was common to use them as a logical operation like you have done.

IF (x=1) & (y=2) THEN z=4

Ends up working when both are true because 1 & 1 = 1, or TRUE & TRUE = TRUE.  When used like this the code is slightly more efficient then an AND.

The AND operator generates different code.  It is a blocking operator, meaning that if the first operand is FALSE then the second one is not tested because the statement is false if one or more of the operands is false.

And that is the reason you would want to use AND over &.  Consider the case of dereferencing a pointer.  Dereferencing a NULL pointer will generate an exception so this statement would be wrong to use:

pointer p
if( p<>NULL) & (#<INT>p = 100) THEN PRINT "Help Me"

Since it is a bitwise AND both parts of the statement are executed before the & is performed.  The dereference happens whether the pointer is NULL or not.  So the correct code would use the AND operator:

pointer p
if( p<>NULL) AND (#<INT>p = 100) THEN PRINT "Help Me"

The code generated skips the dereference when P is NULL.  Such cases are common in programming. 

Paul.
Title: Re: IBasic Pro stuff I can't find in EBasic Doc, so is it still valid?
Post by: billhsln on January 14, 2007, 09:39:22 AM
Thanks, Paul, for the excellent explanation.  I understand why it works and why I should really use AND and OR rather than & and |.  Not sure why I thought I had to use & and | instead of AND and OR in an IF statement.  Must have read it some where, but obviously I was using it incorrectly.

So, thanks again,
Bill