New installation CW10.6, casting errors (printf cant show negative values)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

New installation CW10.6, casting errors (printf cant show negative values)

976件の閲覧回数
CarlFST60L
Senior Contributor II

Code snippet:

    printf("test result = %i\r\n", 0xFF);

    printf("test result = %i\r\n", (char)0xFF);

Simple code that I have run on my cygwin gcc, codepad.org and visual studio all return the expected result:

test result = 255

test result = -1

Run this code on my new MQX4.1.1 build with up to date CW10.6 (win7 64bit) and get:

test result = 255

test result = 255

Problem is this worked on my old windows build (also a fresh installation), so what changed? what setting could affect this?

Obviously I have dumbed this down but this is a serious probelm for my code which has been working on MQX4.1.1 up to date, and now has stopped (all i did was rebuild my computer and fresh install this).

2 返答(返信)

873件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi Carl,

Weird.  I see it too.

Will report to the MQX Development team for them to look into.

Wondering if the default type casting of "char" has changed.

If I run your test with:

   printf("test result = %u\r\n", 0xFF);
   printf("test result = %d\r\n", (char)0xFF);
   printf("test result = %d\r\n", (signed char)0xFF);

I get on terminal this:

test result = 255

test result = 255

test result = -1

Regards,

David

873件の閲覧回数
CarlFST60L
Senior Contributor II

Its actually far worse for us. I have a project that that is around 512K and there are strange things happening with variables being passed to functions, and worse, when two variables are being cast and compared with each other the results are wrong.

0 件の賞賛
返信