IF child.method(parameter) == TRUE
or
IF child.method(parameter) == FALSE
or
IF child.method(parameter)
or
IFNOT child.method(parameter)
or
any of a variety of ways ... all valid
You must be doing something wrong to get an incorrect comparison. Show your code rather than 'I did this and it didn't work'. It would save a lot of time and effort. There's no specific 'proper way'. These are Boolean expressions with FALSE being zero and TRUE being non-zero just like in C++.
@idbruce, the attached example comes directly from the propeller manual. From my experience, C/C++ constructs are very similar to SPIN at least in this example.
FALSE has a value of zero -- that's the case for both Spin and C/C++. A non-zero value is generally treated as TRUE in most case. However, if you're testing specifically for the value of TRUE, then this is different between Spin and C/C++. TRUE has a value of 1 in C/C++ and $ffffffff in Spin.
In some code I have forced the return value to match Spin's true and false constants by doing this
return (resultvalue <> 0)
If the return value is non-zero (true) it will be promoted to $FFFFFFFF which matches Spin's constant value for true. This ensures that code like this:
if object.method() == true
will work. Spin will promote non-zero to true if you leave out the equality test:
if object.method()
' return was true
Of course, if you want to write code that will work and is absolutely clear you could always test for false instead
if object.method() <> false
... though this is a negative test, and sometimes just doesn't 'feel' right.
This particular method suffers from NewDataAvailable being a byte rather than a long (last time I checked). While it doesn't matter for FALSE it does for TRUE as JonnyMac pointed out ($FF vs $FFFFFFF).
PUB GetDataFields(DataField1Pointer, DataField2Pointer)
'This method can only be called once by the
'parent object, and then DataField1 and DataField2
'are set to zero.
' LONGMOVE(DataField1Pointer, @DataField1, 1)
' LONGMOVE(DataField2Pointer, @DataField2, 1)
LONG[DataField1Pointer] := DataField1
LONG[DataField2Pointer] := DataField2
' SetDataFieldsToZero
' NewDataAvailable := FALSE
Keeps returning values of zero with only one write and one read ARRRG
In the method ReceiveDataWithCRC there is the following call ParseReceivedData(@MessageBuffer, @DataField1, @DataField2), ParseReceivedData seperates the message buffer at the colon delimiter creating two decimal values and assigning the values to DataField1 and DataField2. Retrieval of these values are attempted in the parent with the following call:
Comments
or
IF child.method(parameter) == FALSE
or
IF child.method(parameter)
or
IFNOT child.method(parameter)
or
any of a variety of ways ... all valid
You must be doing something wrong to get an incorrect comparison. Show your code rather than 'I did this and it didn't work'. It would save a lot of time and effort. There's no specific 'proper way'. These are Boolean expressions with FALSE being zero and TRUE being non-zero just like in C++.
you have a very good style to bring things to the point. Clear and short. I like this way.
So I gave myself a new target: write postings clear and short.
Thank you for initiating this.
best regards
Stefan
FALSE has a value of zero -- that's the case for both Spin and C/C++. A non-zero value is generally treated as TRUE in most case. However, if you're testing specifically for the value of TRUE, then this is different between Spin and C/C++. TRUE has a value of 1 in C/C++ and $ffffffff in Spin.
Dave
If the return value is non-zero (true) it will be promoted to $FFFFFFFF which matches Spin's constant value for true. This ensures that code like this:
will work. Spin will promote non-zero to true if you leave out the equality test:
Of course, if you want to write code that will work and is absolutely clear you could always test for false instead
... though this is a negative test, and sometimes just doesn't 'feel' right.
@Mike - Excerpts are shown below.
IF Slave.IsNewDataAvailable == TRUE
@Dave - In C++ I never had any trouble comparing boolean function return values. Return TRUE or FALSE and compare to TRUE or FALSE
@Jon - That was very interesting.
That's what I want.
Thanks guys
Bruce
Thanks for the tip, it is now a long. I am having problems getting this simulation going.
Still working on it though. Getting it working should be right around the corner.
Bruce
If you are still listening....
Keeps returning values of zero with only one write and one read ARRRG
In the method ReceiveDataWithCRC there is the following call ParseReceivedData(@MessageBuffer, @DataField1, @DataField2), ParseReceivedData seperates the message buffer at the colon delimiter creating two decimal values and assigning the values to DataField1 and DataField2. Retrieval of these values are attempted in the parent with the following call:
Slave.GetDataFields(@DataField1, @DataField2)
Sorry for that, my fault, got sidetracked.
Bruce