Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual
Product codes
SW006021-1
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 199
As more features of printf() are detected, the size of the code generated for the
printf()
printf()
function will increase.
If the format string in a call to printf() is not a string literal as above, but is rather a
pointer to a string, then the compiler will not be able to reliably predict the printf()
usage, and so it forces a more complete version of printf() to be generated.
pointer to a string, then the compiler will not be able to reliably predict the printf()
usage, and so it forces a more complete version of printf() to be generated.
However, even without being able to scan printf() placeholders, the compiler can
still make certain assumptions regarding the usage of the function. In particular, the
compiler can look at the number and type of the additional arguments to printf()
(those following the format string expression) to determine which placeholders could
be valid. This enables the size and complexity of the generated printf() routine to
be kept to a minimum even in this case.
still make certain assumptions regarding the usage of the function. In particular, the
compiler can look at the number and type of the additional arguments to printf()
(those following the format string expression) to determine which placeholders could
be valid. This enables the size and complexity of the generated printf() routine to
be kept to a minimum even in this case.
For example, if printf() was called as follows:
printf(myFormatString, 4, 6);
the compiler could determine that, for example, no floating-point placeholders are
required and omit these from being included in the printf() function output. As the
arguments after the format string are non-prototyped parameters, their type must
match that of the placeholders.
required and omit these from being included in the printf() function output. As the
arguments after the format string are non-prototyped parameters, their type must
match that of the placeholders.
No aspect of this operation is user-controllable (other than by adjusting the calls to
printf()
printf()
); however, the actual printf() code used by a program can be observed.
If compiling a program using printf(), the driver will leave behind the pre-processed
version of doprnt.c. This module, called doprnt.pre in your working directory, will
show the C code that will actually be contained in the printf routine. As this code has
been pre-processed, indentation and comments will have been stripped out as part of
the normal actions taken by the C pre-processor.
version of doprnt.c. This module, called doprnt.pre in your working directory, will
show the C code that will actually be contained in the printf routine. As this code has
been pre-processed, indentation and comments will have been stripped out as part of
the normal actions taken by the C pre-processor.