type short won't evaluate in relation?

General discussion on mikroC PRO for 8051.
Post Reply
Author
Message
djolea
Posts: 24
Joined: 15 Oct 2011 11:56

type short won't evaluate in relation?

#1 Post by djolea » 24 Apr 2014 10:58

This simple relation won't evaluate properly if type is short(or char) but if type is int(or long), it will?

Code: Select all

  unsigned short temp;
  short temp1;
  short Set_value;
  short Set_diff;

void main() {
  do {
  
            temp1=temp;

          if(temp1 >= (Set_value+Set_diff)){

                     P0 = 0x00;
                  }

                 else if (temp1 < (Set_value-Set_diff)){

                            P0 = 0xFF;

                          }

}
}
Parenthesis or no parenthesis, relation is true only with int type.
Is this a bug or I do something wrong?
sw is mikroC PRO for 8051 3.50

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: type short won't evaluate in relation?

#2 Post by dejan.odabasic » 30 Apr 2014 09:10

Hello,

Thank you for reporting this problem.
Our developer will solve it as soon as possible.

As a workaround you can cast a temp1 variable:

Code: Select all

    if ((unsigned)temp1 < (Set_value-Set_diff)){
      P0 = 0xFF;
    }
Best regards.

djolea
Posts: 24
Joined: 15 Oct 2011 11:56

Re: type short won't evaluate in relation?

#3 Post by djolea » 02 May 2014 09:28

Thanks for the reply, but you didn't test your "workaround" have you?
Yor solution works only if temp1 is positive, and i remind you that it is type of short, not unsigned. Also first part of relation won't evaluate in any case..
Regards

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: type short won't evaluate in relation?

#4 Post by dejan.odabasic » 05 May 2014 12:29

Hello,

Yes, you are correct, suggested workaround referees only to this variant (temp1>0).
Solution for this problem will be available in compiler update.

Best regards.

Post Reply

Return to “mikroC PRO for 8051 General”