Logical Operators on Words

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

Logical Operators on Words

#1 Post by JimKueneman » 07 Feb 2011 04:57

Is this normal:

Code: Select all

const
  MASK = $0001;

type
  TMyRec = record
     Bob: Word
  end;

var
  MyRec: TMyRec;

begin
  MyRec.Bob := $FF01;
  MyRec.Bob := MyRec.Bob and not MASK 
end; 
What happens is the upper byte is also cleared.

To fix do this:

Code: Select all

const
  MASK = Word($0001);
For a compiler/MCU that is based on words this seems like the compiler should be able to see I am working with words and I should not have to remember to always force constants into words.

Jim

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Logical Operators on Words

#2 Post by zristic » 07 Feb 2011 09:34

It defaults to byte, in order to generate smaller code. Yes, you have to explicitly specify word if you want word.

Post Reply

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