AnsweredAssumed Answered

Printf issue, MC56f82748

Question asked by Colin Cameron on Aug 7, 2015
Latest reply on Aug 7, 2015 by John Winters

Hi,

 

I'm using the TWR-56F8200 board with the MC56f82748 chip and code warrior 10.6 Build Id 140329.

 

The following code behaves oddly, all optimization is off and it's a basic barebones project from the wizard.

 

#include <stdio.h>

 

int main(void)

{

  int temp = 2;

  printf("%i\n", temp);

  printf(" %i\n", temp);

  while (1) { }

}

 

The output I get is:

 

%i

2


It seems that the first call to printf reads the format variables (i.e. it just prints the string, I tried a few but that's the simplest example).

 

Interestingly it doesn't happen if I add a 'char c[] = "";'. Looking at the debug it appears to happen when the string is stored at location 0 -- debugging into the printf it seems to fail the 'strchr(format_ptr, '%'))' test in the code.

 

Is there a way I can avoid this apart from adding the blank string (which will get removed in the optimization when I turn it on), or a dummy printf earlier.

Outcomes