AnsweredAssumed Answered

Problems with printf variable argument parsing

Question asked by Tho Borawski on Feb 5, 2015
Latest reply on Feb 6, 2015 by Tho Borawski

For Codewarrior V10.5 with EWL, I have been having problems getting
printf to process the argument list correctly.  As an example, for two

test variables:


unsigned short locTestNum = 5;
float locTestFloat = 1.234;


When I execute:


printf("{Float=%8.3f} {Int= %hu}\n",locTestFloat,locTestNum);


The result is:


{Float=0.000} {Int= 5}

I realize that there are library build options (such as
_EWL_FLOATING_POINT_PRINTF_SCANF) that may cause such a problem, but I have used sprintf
in the past with floats with no problems.


As a sidenote: I found that I had to initialize the stdout file handle
to get printf to work via WriteUARTN. The following are the settings I used:


stdout->mode.open_mode = __create_if_necessary;
stdout->mode.buffer_mode = _IONBF;
stdout->mode.io_mode = __write_mode;
stdout->mode.file_kind = __console_file;   
stdout->state.error = 0;
stdout->state.io_state = __writing;       
stdout->write_proc =  __write_console;  //located in /src/sys/uart_console_io.c calls WriteUARTN directly
stdout->read_proc =  __read_console;
stdout->buffer = stdout_buff;
stdout->buffer_ptr = stdout_buff;
stdout->buffer_size = sizeof(stdout_buff);
stdout->buffer_len = sizeof(stdout_buff);