Skip to content

printf format warnings (-Wformat) regarding type definition change from Arduino 2 to Arduino 3 for uint32_t and int32_t #9546

@mathieucarbou

Description

@mathieucarbou

Platformio:

PLATFORM: Espressif 32 (2024.4.12+sha.9d4b8e6) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash

platform = espressif32
platform_packages=
  platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0-rc1
  platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1
board = esp32dev

Switching to Arduino 3 leads to several printf warnings regarding type definition changed from int to long.

Example:

/Users/mat/Data/Workspace/me/WebSerialLite/examples/demo_ap/demo_ap.ino: In function 'void loop()':
/Users/mat/Data/Workspace/me/WebSerialLite/examples/demo_ap/demo_ap.ino:53:22: warning: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=]
   53 |     WebSerial.printf("Free heap=[%u]\n", ESP.getFreeHeap());
      |                      ^~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~
      |                                                         |
      |                                                         uint32_t {aka long unsigned int}

The problem is that printf format is setup by the developer according to the expected type of the argument. If those type change, the format might become incorrect.

In the example above, fixing the format for Arduino 3 would make it wrong for Arduino 2...

What would be the solution for library developer to maintain a compatibility with Arduino 2 & 3 in such case ?

I saw some old issues referencing this same problem but they seemed to be closed or left:

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: SolvedThe issue has been resolved and requires no further action.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions