With the attached code if Debug =0 Leds are always ON, if Debug = 1 they are blinking.
Debug = 0 use var bool, Debug = 1 use Int.
Doe's my coding is frong in using var bool ?
Problem with var bool
Moderator: Benj
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Problem with var bool
Hello.
If you change:
To:
This works. The '!' is a logical-not, and 'NOT' is bitwise. In C, both these operations should work, but I believe BoostC treats 'bool' as C++ would.
For curiosty, this is why it does not work:
Jonny
If you change:
Code: Select all
LedBool0 = NOT LedBool0
LedBool1 = NOT LedBool1
Code: Select all
LedBool0 = !LedBool0
LedBool1 = !LedBool1
For curiosty, this is why it does not work:
- The LedBool0 variable has a value '1'
- The compiler takes the 1 bit LedBool0 and converts to a byte, 0x01
- The byte is inverted, so is 0xFE
- A Boolean conversion is performed to write back to LedBool0 - 0xFE is non-zero so is converted to '1'
- The value is now written back, but unchanged
Jonny
Re: Problem with var bool
Thank's for the quick answer.
The problem is that in simutation there is no difference !
The problem is that in simutation there is no difference !
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Problem with var bool
No, the simulation behaves as C would. If you used a different ANSI-C compliant compiler like Hi-Tec this would behave as simulation does. In future versions it would be nice to provide a "Simulate 'bool' as C++" option in the project or global settings and provide warnings on compilation or simulation but until then I would say just use logical operators with Boolean values and you will be OK.
Cheers,
Jonny
Cheers,
Jonny
Re: Problem with var bool
Sorry if J don't understand your answere.
J use for compiling boostc delivered with FlowCode.
In FlowCode simulation leds are blinking with Debug = 0 or Debug = 1.
J use for compiling boostc delivered with FlowCode.
In FlowCode simulation leds are blinking with Debug = 0 or Debug = 1.
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Problem with var bool
Hi. Thats OK - Flowcode is shipped with BoostC as its compiler, but can use other C compilers if you wish to change this.
Because Flowcode compiles to C Flowcode simulates as C code would. But BoostC 'bool' values behave like they would in C++, which is subtly different.
As a general rule, only use the logical operators that are designed to work with Boolean values (don't use 'NOT', use '!') as Boolean is not an arithmetic type, in the same way that strings are not arithmetic types. Also, try not to mix types - adding a bool to a float for example may be allowed, but does not make much sense.
For reference, here are the types supported in Flowcode and the operators you should use on them:
bool
!, ||, &&, ==, !=, |, &, ^
(Be careful using |, &, ^ and don't mix bools with ints)
int, uint, etc
All operators
float
All operators except: &, |, ^, ~, <<, >>
string
+ (String concatenation only)
I hope this is more clear, and I have not complicated things further!
Jonny
Because Flowcode compiles to C Flowcode simulates as C code would. But BoostC 'bool' values behave like they would in C++, which is subtly different.
As a general rule, only use the logical operators that are designed to work with Boolean values (don't use 'NOT', use '!') as Boolean is not an arithmetic type, in the same way that strings are not arithmetic types. Also, try not to mix types - adding a bool to a float for example may be allowed, but does not make much sense.
For reference, here are the types supported in Flowcode and the operators you should use on them:
bool
!, ||, &&, ==, !=, |, &, ^
(Be careful using |, &, ^ and don't mix bools with ints)
int, uint, etc
All operators
float
All operators except: &, |, ^, ~, <<, >>
string
+ (String concatenation only)
I hope this is more clear, and I have not complicated things further!
Jonny