Thursday, September 21st 2017, 10:45am UTC+2

You are not logged in.

  • Login
  • Register

knuta

Beginner

Date of registration: Nov 25th 2012

Posts: 26

1

Wednesday, May 17th 2017, 7:45am

printf("%02d", 5) prints "2d" instead of "05"

I've discovered that specifying the width of an integer in SEGGER Embedded Studio Release 3.12 Build 2017021000.31105 Linux x64 makes it fail to print a number, and instead prints part of the format string.

Consider this code:

Source code

1
2
3
4
    int i = 5;
    printf("Hello World %d!\n", i);
    printf("Hello World %2d!\n", i);
    printf("Hello World %02d!\n", i);


Expected output:

Source code

1
2
3
Hello World 5!
Hello World  5!
Hello World 05!


Actual output:

Source code

1
2
3
Hello World 5!
Hello World d!
Hello World 2d!


Steps to reproduce:

  • File -> New Project
  • Select "Create the project in a new solution"
  • Select "A C/C++ executable for a Cortex-M processor.", click Nex
  • Select "nRF52832_xxAA", click next
  • Leave everything as defaults, click next until wizard completes
  • Replace the "Hello World" printf with my code example above
  • Run the code and watch the Debug Console

I'm not sure if other devices are affected. The nRF52832_xxAA is a Cortex-M4 device.

knuta

Beginner

Date of registration: Nov 25th 2012

Posts: 26

2

Wednesday, May 17th 2017, 7:59am

Update: If I select "A C/C++ executable for a Cortex-M processor (internal tools and external GNU tools)." printf works as expected.

rgal

Beginner

Date of registration: Feb 16th 2016

Posts: 8

3

Saturday, July 8th 2017, 8:17pm

Hi,

I has similiar problem, in project options->code->printf/scanf->Printf Width/Precision Supported must be set to YES.