Jump to content

Strange Literal Parsing

Recommended Posts

Hi Pavel,


boostc v7.01



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 ??????






Andy Leiper


Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

  • Create New...