Skip to content

%zu not supported by newlib's printf in Arduino_STM32 toolchain #38

@fronders

Description

@fronders

People have been reporting same problem when using newlib printf. This is what's included into Arduino STM32 toolchain and so the %zu format specifier doesn't work, and instead of putting the number it puts "zu" into the resulting string.

As a consequence the getFileBlock() just freezes and never returns

size_t cmd_len = filename.length() + 32;
char* cmd = sara_r5_calloc_char(cmd_len);
sprintf(cmd, "at+urdblock=\"%s\",%zu,%zu\r\n", filename.c_str(), offset, requested_length);
sendCommand(cmd, false);

Here's the debugger screenshot:
image

Changing those to %lu fixes the issue.

UPD:
By default, the sketches use newlib nano option which passes linker flags --specs=nano.specs
I'm usually compiling using the "newlib nano + float printf" which is --specs=nano.specs -u _printf_float cause I need floats support in printfs. After switching to the full-featured "newlib standard" (which doesn't pass any additional flags) the %zu specifier worked! I assume the nano option supplied with ARM toolchain newlib is built without C99 formatting support. But I don't use it because it makes the flash size (program storage space) explode - the same sketch went from 82376 to 188208 bytes, as well as RAM went +1kB!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions