Migrating projects with the custom fputc() function

Technical Note 220216






3/1/2022 4:16 PM


Some projects with a custom fputc() function generate no output when they are migrated to EWARM 9.20.1 or later version.


This Technical Note applies to projects matching all these points:

  • Uses Full Library configuration, in other words the _DLIB_FILE_DESCRIPTOR = 1.
  • Only uses the printf() function and/or putchar() function for output.
  • Has implemented a custom fputc() function.

Other migrated projects are not affected.


  1. Evaluate if the project needs Full library configuration. If not, switching to Normal library configuration could solve the problem.
  2. If Full library configuration is needed: Implement __write() instead of fputc().

Note: The recommended way to do retargeting is to implement __write(). This is described in the IAR C/C++ Development Guide, in the chapter The DLIB runtime environment, in the section Retargeting—Adapting for your target system, under the heading Standard streams for input and output.


EWARM 9.20.1 introduced an optimization in the run-time library.

  • The aim of that optimization is to avoid including (in the linked .out file) file descriptor (including malloc()).
  • In other words, the optimization shrinks linked output in 9.20.1 and later versions.


This link holds two example projects for retargeting printf() to UART1 when fputc() and __write() has been retargeted. The example (on the MCB2130 board) shows how to migrate from EWARM 9.10.2 to EWARM 9.20.2.


For migrated projects where this ‘no output’ issue occurs, the change from a custom fputc() function to a custom __write() function solves the issue.

A benefit is that the size of the linked .out file shrinks, when doing retargeting with a custom __write() function.

All product names are trademarks or registered trademarks of their respective owners.

We do no longer support Internet Explorer. To get the best experience of iar.com, we recommend upgrading to a modern browser such as Chrome or Edge.