Skip to content

Conversation

@htibosch
Copy link
Contributor

Description

As an option, the code in FreeRTOS+TCP can produce logging.

In three modules, my GNU compiler gives many warnings about the printf format used:

FreeRTOS_DHCPv6.c
FreeRTOS_IPv6_Utils.c
FreeRTOS_RA.c

For example in FreeRTOS_IPv6_Utils.c :

FreeRTOS_debug_printf( ( "%lu + %lu is larger than %lu\n",
                         uxIndex,
                         uxHopSize,
                         uxBufferLength ) );

gives 3 warnings of this type:

warning: format '%lu' expects argument of type 'long unsigned int',
but argument 3 has type 'size_t {aka unsigned int}' [-Wformat=]

In other modules, we solved this problem casting to either int or unsigned and using %u:

FreeRTOS_debug_printf( ( "%u + %u is larger than %u\n",
                         ( unsigned ) uxIndex,
                         ( unsigned ) uxHopSize,
                         ( unsigned ) uxBufferLength ) );

The logging is the same, and the warnings have gone, independent of the platform.

Earlier I wrote about my multi-platform testing of various printf formats.

Test Steps

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@htibosch htibosch requested a review from a team as a code owner March 17, 2024 06:28
@htibosch
Copy link
Contributor Author

/bot run uncrustify

@tony-josi-aws tony-josi-aws merged commit 05f6eca into FreeRTOS:main Apr 3, 2024
@htibosch htibosch deleted the avoid_compiler_warnings_about_printf branch September 17, 2025 06:04
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.

3 participants