The behaviour of the simulation is different to the one on the target when using a negation of a boolean variable foo (foo = ~foo). The C-code itself looks okay and works in the simulator but on the target the respective expression doesn't get evaluated properly...
As a workaround I avoided the “~” and it works now also on the target but I wanted to report that at least.
edit: I'm using the PIC24/dsPIC version of Flowcode
Negation of boolean by “~” doesn't work with MCP-Compiler
Moderator: Benj
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: Negation of boolean by “~” doesn't work with MCP-Compile
If you require a logical NOT (meaning everything not equal to zero becomes zero and zero becomes a non zero value) it is better to use the exclamation mark ('!'). Depending on the compiler the bitwise NOT (or two complement operator) creates unexpected results. Not 1 would be 0 if a boolean is stored as 1 bit, however for most compilers a boolean is stored in a byte, meaning not 0000 0001 becomes 1111 1110 which is <> 0.
The simulator should implement the reality as generated by the compiler, not the ideal world.
The simulator should implement the reality as generated by the compiler, not the ideal world.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
Re: Negation of boolean by “~” doesn't work with MCP-Compile
Hi kersing, thanks for your fitting solution. I also tried "NOT" but didn't think on "!"...
It works well now as you said.
I just found time now to try every of your solutions (god bless the weekend).
It works well now as you said.
I just found time now to try every of your solutions (god bless the weekend).