View previous topic :: View next topic |
Author |
Message |
Guest
|
What is wrong with this compiler? |
Posted: Thu Oct 09, 2008 8:00 am |
|
|
What is wrong with this compiler?
Code: | int1 data[10];
int1 p_error;
if (data[index] ^ data[index-1] ^ data[index-2] ^ data[index-3] ^ data[index-4]) { p_error=1; } |
Must split it out to:
Code: | int1 pbit,bit,bit1,bit2,bit3,bit4
bit = data[index];
bit1 = data[index-1];
bit2 = data[index-2];
bit3 = data[index-3];
bit4 = data[index-4];
pbit = bit1 ^ bit2 ^ bit3 ^ bit4; |
Compiler v 4.074
Some hints? |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 09, 2008 8:28 am |
|
|
Thats nice.
To be fair, you have not given any indication of what the problem is, nor have you shown any results or explained the outcome of your code.
Further more, you have not supplied enough code to even compile a program let alone debug it from the little info you have shown.
None the less, someone most likely will come up with some helpfull info for you.
Either, give a complete program and show output and explain the problem or give a lot more detail than what is here.
I will not be trying to recreate the problem (whatever it is) with the simple snippets you have shown.
Sorry |
|
|
Guest
|
|
Posted: Thu Oct 09, 2008 8:45 am |
|
|
Sorry here are a working ex.
It compile BUT look at the ASM file!!!
Code: | void CompError() {
int1 data[10];
int1 p_error=0;
int index=0;
for (index=0; index<10; index++) { data[index] = index; }
if (data[index] ^ data[index-1] ^ data[index-2] ^ data[index-3] ^ data[index-4]) { p_error=1; }
}
|
|
|
|
Guest
|
|
Posted: Thu Oct 09, 2008 9:34 am |
|
|
Try:
Code: | (data[index] && 1) ^ (data[index-1] && 1)..... |
It work for me |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Oct 09, 2008 12:35 pm |
|
|
You should also tell, which target respectively compiler type your talking about. I guess, there is a problem with accessing the correct bit position? I remember some issues with bit fields (and possibly bit arrays), that already existed in V3. |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 09, 2008 2:00 pm |
|
|
Seriously, you have to remember that the compiler has no error checking on array indexes. Your array allows locations 0 to 9, but your first loop accesses locations -4, -3, -2, -1 and 0. You need to perform error checking to have any hope of getting sensible results...
Best Wishes |
|
|
|