April 27, 2024, 06:20:14 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


IBasic Pro stuff I can't find in EBasic Doc, so is it still valid?

Started by billhsln, January 13, 2007, 10:45:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

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...
When all else fails, get a bigger hammer.

Ionic Wind Support Team

They are in the docs.  See Language->Operators.  Same place they were in the IBasic Pro docs.

Ionic Wind Support Team

mrainey

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
Software For Metalworking
http://closetolerancesoftware.com

billhsln

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
When all else fails, get a bigger hammer.

Ionic Wind Support Team

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.
Ionic Wind Support Team

billhsln

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
When all else fails, get a bigger hammer.