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

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • 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. int i = 5;
    2. printf("Hello World %d!\n", i);
    3. printf("Hello World %2d!\n", i);
    4. printf("Hello World %02d!\n", i);


    Expected output:

    Source Code

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


    Actual output:

    Source Code

    1. Hello World 5!
    2. Hello World d!
    3. 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.