This section provides details about the precise syntax of conversion
specifications that can appear in a
Characters in the template string that are not part of a conversion specification are printed as-is to the output stream. Multibyte character sequences (see section Extended Characters) are permitted in a template string.
The conversion specifications in a
printf template string have
the general form:
% flags width [ . precision ] type conversion
For example, in the conversion specifier `%-10.8ld', the `-'
is a flag, `10' specifies the field width, the precision is
`8', the letter `l' is a type modifier, and `d' specifies
the conversion style. (This particular type specifier says to
long int argument in decimal notation, with a minimum of
8 digits left-justified in a field at least 10 characters wide.)
In more detail, output conversion specifications consist of an initial `%' character followed in sequence by:
int. If the value is negative, this means to set the `-' flag (see below) and to use the absolute value as the field width.
int, and is ignored if it is negative. If you specify `*' for both the field width and precision, the field width argument precedes the precision argument. Other C library versions may not recognize this syntax.
int, but you can specify `h', `l', or `L' for other integer types.)
The exact options that are permitted and how they are interpreted vary between the different conversion specifiers. See the descriptions of the individual conversions for information about the particular options that they use.
With the `-Wformat' option, the GNU C compiler checks calls to
printf and related functions. It examines the format string and
verifies that the correct number and types of arguments are supplied.
There is also a GNU C syntax to tell the compiler that a function you
write uses a
printf-style format string.
See section `Declaring Attributes of Functions' in Using GNU CC, for more information.
Go to the first, previous, next, last section, table of contents.