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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

449 Views
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 Replies

346 Views
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

346 Views
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 Kudos