Jump to content
Sign in to follow this  
Andrew Leiper

Strange Literal Parsing

Recommended Posts

Hi Pavel,

 

boostc v7.01

PIC18F2525

 

Please see the comments in the code below.

It seems with this one as if the compiler is ignoring the brackets and so evaluating (-1/2) to give 0.

 

////////////////////////////

#include <system.h>

 

#define BAD1 ((unsigned short)-1)

#define BAD2 (BAD1 / 2)

 

#define GOOD1 (0xFFFF)

#define GOOD2 (GOOD1 / 2)

 

 

unsigned short p;

void main(void)

{

p = GOOD1; //p == 0xFFFF as expected

p = GOOD2; //p == 0x7FFF as expected

 

p = BAD1; //p == 0xFFFF as expected

p = BAD2; //p == 0 ??????

}

/////////////////////////////////////////////////////

 

Cheers,

 

Andy Leiper

IET Ltd

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×