3.4.6 How Do I Use Printf to Send Text to a Peripheral?

The printf function does two things: it formats text based on the format string and placeholders you specify and sends (prints) this formatted text to a destination (or stream). You may choose the printf output go to an LCD, SPI module or USART, for example.

For more on the standard printf function, see the Microchip Unified Standard Library Reference Guide.

To have the compiler statically analyze what format strings are passed to the printf function, you may use the -msmart-io option (5.7.1 Options Specific to PIC32C/SAM Devices). Also you may use the -Wformat option to specify a warning when the arguments supplied to the function do not have types appropriate to the format string specified (see 5.7.5 Options for Controlling Warnings and Errors).

If you wish to create your own printf-type function, you will need to use the attributes format and format_arg as discussed in 16.2.1 Function Attributes.