Evaluation Issue

General discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Evaluation Issue

#1 Post by JimKueneman » 31 Jan 2012 04:56

Anyone else see this:

Code: Select all


const
  CAN_LAYER_STATE_TRANSMIT_PENDING    = $0001;
  CAN_LAYER_STATE_TRANSMITTED         = $0002;
  CAN_LAYER_STATE_SUCCESS             = $0004;
  CAN_LAYER_STATE_ERROR               = $0008;
  CAN_LAYER_STATE_INITIAL_LOAD = CAN_LAYER_STATE_TRANSMIT_PENDING or CAN_LAYER_STATE_SUCCESS;

  TCAN_Layer_Buffer = record                                                    
    Packet: TCAN_Packet;
    State: Word;                                                                // See the TCAN_LAYER_STATE_xxx constants
  end;
  PCAN_Layer_Buffer = ^TCAN_Layer_Buffer;
  
var
  CAN_Layer_Buffer: TCAN_Layer_Buffer;

     CAN_Layer_Buffer.State := CAN_LAYER_STATE_INITIAL_LOAD;  // Assume Success

// State = 5 as expected

      CAN_Layer_Buffer.State := CAN_Layer_Buffer.State or CAN_LAYER_STATE_TRANSMITTED and not CAN_LAYER_STATE_TRANSMIT_PENDING;

// State = 7 Why????????

      CAN_Layer_Buffer.State := CAN_Layer_Buffer.State or CAN_LAYER_STATE_TRANSMITTED;
      CAN_Layer_Buffer.State := CAN_Layer_Buffer.State and not CAN_LAYER_STATE_TRANSMIT_PENDING;

// State = 6 as expected

Jim

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Evaluation Issue

#2 Post by VCC » 31 Jan 2012 16:27

I looks like it is evaluated like:

Code: Select all

CAN_Layer_Buffer.State := (CAN_Layer_Buffer.State or CAN_LAYER_STATE_TRANSMITTED) and not CAN_LAYER_STATE_TRANSMIT_PENDING;
instead of

Code: Select all

CAN_Layer_Buffer.State := CAN_Layer_Buffer.State or (CAN_LAYER_STATE_TRANSMITTED and not CAN_LAYER_STATE_TRANSMIT_PENDING);
:(

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Evaluation Issue

#3 Post by janko.kaljevic » 31 Jan 2012 16:40

Hello,

Please notice that expression from Jim's post is calculated as:

Code: Select all

CAN_Layer_Buffer.State := CAN_Layer_Buffer.State or (CAN_LAYER_STATE_TRANSMITTED and not CAN_LAYER_STATE_TRANSMIT_PENDING);
just like it should.

Best regards.

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Evaluation Issue

#4 Post by VCC » 31 Jan 2012 16:51

Sorry, wrong calculations. However I always use parentheses to be sure.

JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Re: Evaluation Issue

#5 Post by JimKueneman » 01 Feb 2012 17:43

Oh my has it been that long since writing statements like this in Turbo Pascal for Windows and Window 3.x. I had completely forgotten the precidence difference between or and and....

Thanks,
Jim

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 General”