|
|
View previous topic :: View next topic |
Author |
Message |
poolplayer
Joined: 17 Jul 2007 Posts: 2
|
Found a BUG regarding int1=int1 |
Posted: Wed Jul 18, 2007 2:14 am |
|
|
Hi,
I think, I found a bug regarding the = Operator.
My tested processors: 18F1220 and 18F6720
My new compiler version: 4.044
(With compiler version 3.249 the error doesn't occur!)
Here is the Code of the bad Code:
Code: |
void main(void) {
some_inits();
while(1) {
a = input(PIN_B2);
b = 1; // init b
output_bit(PIN_B5, a); // will be HIGH if input(PIN_B2)==1 ; will be LOW if input(PIN_B2)==0
output_bit(PIN_B6, b); // will always be HIGH
b = a;
output_bit(PIN_B7, b); // ERROR: will ALWAYS (!!!!!) be HIGH
}
|
Here is the Listing of the bad Code
.................... while(1) {
.................... a = input(PIN_B2);
0834: BSF F93.2
0836: BCF 7B.0
0838: BTFSC F81.2
083A: BSF 7B.0
.................... b = 1;
083C: BSF 7B.1
.................... output_bit(PIN_B5, a); // will be HIGH if input(PIN_B2)==1 ; will be LOW if input(PIN_B2)==0
083E: BTFSC 7B.0
0840: BRA 0846
0842: BCF F8A.5
0844: BRA 0848
0846: BSF F8A.5
0848: BCF F93.5
.................... output_bit(PIN_B6, b); // will always be HIGH
084A: BTFSC 7B.1
084C: BRA 0852
084E: BCF F8A.6
0850: BRA 0854
0852: BSF F8A.6
0854: BCF F93.6
.................... b = a;
0856: BCF 7B.1
0858: BSF 7B.1
.................... output_bit(PIN_B7, b); // ERROR: will ALWAYS (!!!!!) be HIGH
085A: BTFSC 7B.1
085C: BRA 0862
085E: BCF F8A.7
0860: BRA 0864
0862: BSF F8A.7
0864: BCF F93.7
....................
This could be a workaround:
Code: |
while(1) {
#ignore_warnings NONE
a = input(PIN_B2);
b = 1;
output_bit(PIN_B5, a); // will be HIGH if input(PIN_B2)==1 ; will be LOW if input(PIN_B2)==0
output_bit(PIN_B6, b); // will always be HIGH
b = !!a; // this works!
output_bit(PIN_B7, b); // OK
|
And the listing:
.................... while(1) {
.................... #ignore_warnings NONE
....................
.................... a = input(PIN_B2);
0834: BSF F93.2
0836: BCF 7B.0
0838: BTFSC F81.2
083A: BSF 7B.0
.................... b = 1;
083C: BSF 7B.1
.................... output_bit(PIN_B5, a); // will be HIGH if input(PIN_B2)==1 ; will be LOW if input(PIN_B2)==0
083E: BTFSC 7B.0
0840: BRA 0846
0842: BCF F8A.5
0844: BRA 0848
0846: BSF F8A.5
0848: BCF F93.5
.................... output_bit(PIN_B6, b); // will always be HIGH
084A: BTFSC 7B.1
084C: BRA 0852
084E: BCF F8A.6
0850: BRA 0854
0852: BSF F8A.6
0854: BCF F93.6
.................... b = !!a; // this works!
0856: BCF 7B.1
0858: BTFSC 7B.0
085A: BSF 7B.1
.................... output_bit(PIN_B7, b); // OK
085C: BTFSC 7B.1
085E: BRA 0864
0860: BCF F8A.7
0862: BRA 0866
0864: BSF F8A.7
0866: BCF F93.7
....................
(An other workaround could be to use int8 instead of int1 - but this wastes of course a lot of RAM...)
In the listings you can see the bad bug!
--> Is any PCWH-developper able to fix this bug?
Best Regards |
|
|
Ttelmah Guest
|
|
Posted: Wed Jul 18, 2007 2:59 am |
|
|
Have you read the comments about the change in the way int1 is handled in the readme?....
Conversion to int1 types from int8 (and higher) types, now defaults to using (var & 1), not the old construct of (var != 0).
This was changed, for compatibility with the way ANSI does things. If you use the CCS2 preprocessor directive, it should switch back.
Now, what is 'odd', is that this was already done in 3.249...
However it does mean, that if you want to put a int8 value, into a int1, _you_ will need to force the conversion to be the way you want it. So:
Code: |
void main(void) {
some_inits();
while(1) {
a = input(PIN_B2);
b = 1; // init b
output_bit(PIN_B5, a); // will be HIGH if input(PIN_B2)==1 ; will be LOW if input(PIN_B2)==0
output_bit(PIN_B6, b); // will always be HIGH
//use the logical operator, to force the bit value to reflect the byte
b = (a!=0);
output_bit(PIN_B7, b);
}
|
If you want to report a bug, read the window at the upper right of the forum screen, and report it to CCS. This is a _user_ forum, not CCS bug reporting territory....
Best Wishes |
|
|
poolplayer
Joined: 17 Jul 2007 Posts: 2
|
|
Posted: Wed Jul 18, 2007 3:16 am |
|
|
Sorry, I forgot to post one line of code.
Code: |
void main(void) {
int1 a,b; // I forgott to post this line of code
some_inits();
while(1) {
a = input(PIN_B2);
b = 1; // init b
output_bit(PIN_B5, a); // will be HIGH if input(PIN_B2)==1 ; will be LOW if input(PIN_B2)==0
output_bit(PIN_B6, b); // will always be HIGH
b = a;
output_bit(PIN_B7, b); // ERROR: will ALWAYS (!!!!!) be HIGH
}
|
Quote: |
Have you read the comments about the change in the way int1 is handled in the readme?....
Conversion to int1 types from int8 (and higher) types, now defaults to using (var & 1), not the old construct of (var != 0).
This was changed, for compatibility with the way ANSI does things. If you use the CCS2 preprocessor directive, it should switch back.
Now, what is 'odd', is that this was already done in 3.249...
|
Yes I have...
Quote: |
However it does mean, that if you want to put a int8 value, into a int1, _you_ will need to force the conversion to be the way you want it
|
--> a and b are int1...
Quote: |
If you want to report a bug, read the window at the upper right of the forum screen, and report it to CCS. This is a _user_ forum, not CCS bug reporting territory....
|
Now ok, I will mail this message also to CCS.
This bug (I still think it is a bug) took me more than one day --> perhaps there are some user in this forum who are happy to hear about it...???
Regards |
|
|
Ttelmah Guest
|
|
Posted: Wed Jul 18, 2007 3:33 am |
|
|
OK.
The extra line of code, makes a big difference!. Most definately a bug. What should be there, is one more line between the BCF, and the BSF, with a BTFSC on the other variable.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|