Skip to content

Conversation

mkbanchi
Copy link

We are not able to build with -Werror=format flag due to warnings about some string format specifiers mismatch (%u vs %lu).

This PR fixes the problem by replacing %u/%X specifiers with more portable PRIu32/PRIx32 ones.

@MaJerle
Copy link
Collaborator

MaJerle commented Aug 13, 2025

It makes more sense to cast parameters to (unsigned) if you have warning, rather than replacing with inttypes. If we do it here (with your proposal), it would be better to do it in the lib too, which is way too much for now.

Do you have a godbolt example where we can see the reproducible error?

@mkbanchi
Copy link
Author

Hi,

here an example (however we are using gcc-arm-none-eabi version 13.2.1)

Could you explain why the cast makes more sense? I usually prefer to avoid casts when possible and, in particular for this case:

  • inttypes.h is a standard header and the PRI* exist to make format strings portable when types like uint32_t are involved;
  • i think that the code is clearer: the cast would not indicate the reason why it is there.

However, in this specific case, i think that it is only taste :)

Thanks

@mkbanchi mkbanchi changed the title Use PRIu32/PRIx32 macros instead of harcoded %u/%X specifiers in format strings Use PRIu32/PRIx32 macros instead of hardcoded %u/%X specifiers in format strings Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants