Creator 4.1 update 1: default char unsigned=False will make default char signed?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Just come here to see if I'm the only one have this behavior:

using Creator 4.1 update 1, I found that the option in compiler:

"default char unsigned option = False "

will make the default to signed (i.e. no -fsigned-char appended),

and it was confirmed by compiling and run a check on "char a = 127; a += 1;"

to see if "a == 128" or something else.

Anyone could confirm, or I am the only one has this?

Best,

0 Likes
1 Solution
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

Workaround for the issue as follows-

1. Add -fsigned-char to the custom command line arguments in the Build Settings.

2. Only use char to store text. For any other purpose, use signed char, unsigned char, int8_t, or uint8_t instead.

View solution in original post

0 Likes
5 Replies
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

if "default char unsigned option = False " then it will make the default to signed (i.e. no -fsigned-char appended).It is expected behavior

0 Likes
Anonymous
Not applicable

Even it behaves normal to you, I will try to make more tests on other eval boards (the one in op is

CY8CKIT-043, with CY8C4247-L IIRC) in my hand, since no matter it is

"default char unsigned option = False" or "default char unsigned option = True",

(later one will add "-funsigned-char" to compiler parameters)

the "char a;" declaration always makes it an "unsigned char".

Apparently not works as advertised, IMHO in my case?

I was wondering if there's any other causes, like the codes are too irregular or too complex, or any other.

0 Likes
Anonymous
Not applicable

"default char unsigned option = False "

will make the default to signed (i.e. no -fsigned-char appended),

My bad. This description in the very first post should be:

======================================

"default char unsigned option = False "

will make the default to unsigned (i.e. no -fsigned-char appended),

======================================

. And no matter "False" or "True", it always gives unsigned char if

I didn't assign it "signed" or "unsigned". Like what I typed in previous

post.

0 Likes
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

I reproduced the issue by assigning a char value into a signed long value.

When "unsigned char" type is used, a positive value 0x00000080 is assigned to the long variable b.

GS003283.png

When "signed char" type is used, a negative value 0xFFFFFF80 is assigned.

GS003282.png

When "char" type is used and the "Default Char Unsigned" is set to False, a positive value 0x00000080 is assigned.  So, it was found that the "char" type is handled as "unsigned char" type.

GS003284.png

When "char" type is used and the "Default Char Unsigned" is set to True, a positive value 0x00000080 is assigned.  So, it was found that the "char" type is handled as "unsigned char" type.

GS003285.png

As the conclusion,  The "char" type is handled as "unsigned char" type regardless of the setting of "Default Char Unsigned"

Regards,

Noriaki

AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

Workaround for the issue as follows-

1. Add -fsigned-char to the custom command line arguments in the Build Settings.

2. Only use char to store text. For any other purpose, use signed char, unsigned char, int8_t, or uint8_t instead.

0 Likes