Jump to content

Char Treated As Unsigned


Recommended Posts

	char c;

c = -1;
options = 0;

if (c < 0)
    {
         options = 1;
    }

Does not set options to 1 due to incorrect compile of 'if' statement as it seems to consider 'c' as unsigned.

 

Code generated by 'if' is

    MOVLW 0x00
   SUBWF main_1_c, W
   BTFSC STATUS,C
   GOTO	label268437195

should be

	MOVF _c, W
SUBLW 0x00
BTFSC _status,C
GOTO	label268437195

or better still

	BTFSS _c, 0x80
GOTO	label268437195

 

 

Carolyn

Link to post
Share on other sites

That all being well, except ANSI specs say char is signed, and unsigned char is unsigned.

 

It does cause confusing, and i think it should be changed in the future (with a warning so it does not break peoples code).

 

 

Same with other types etc...

Link to post
Share on other sites

But the BoostC Compiler Help claims

 

Data types

 

Base

1 bit bit, bool

8 bits char,unsigned char,signed char

16 bits short,unsigned short,signed short

16 bits int,unsigned int,signed int

32 bits long,unsigned long,signed long

 

plus compiler is ANSI C so it should support char as signed char

 

If char is not supported as signed it should be in the compiler help as a caveat.

 

Carolyn

Link to post
Share on other sites

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.

Guest
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...
×
×
  • Create New...