You can use the function
parse_printf_format to obtain
information about the number and types of arguments that are expected by
a given template string. This function permits interpreters that
provide interfaces to
printf to avoid passing along invalid
arguments from the user's program, which could cause a crash.
All the symbols described in this section are declared in the header file `printf.h'.
printftemplate string template. The information is stored in the array argtypes; each element of this array describes one argument. This information is encoded using the various `PA_' macros, listed below.
The n argument specifies the number of elements in the array
argtypes. This is the most elements that
parse_printf_format will try to write.
parse_printf_format returns the total number of arguments required
by template. If this number is greater than n, then the
information returned describes only the first n arguments. If you
want information about more than that many arguments, allocate a bigger
array and call
The argument types are encoded as a combination of a basic type and modifier flag bits.
(argtypes[i] & PA_FLAG_MASK)to extract just the flag bits for an argument, or
(argtypes[i] & ~PA_FLAG_MASK)to extract just the basic type code.
Here are symbolic constants that represent the basic types; they stand for integer values.
int, cast to
char *, a null-terminated string.
void *, an arbitrary pointer.
PA_LAST. For example, if you have data types `foo' and `bar' with their own specialized
printfconversions, you could define encodings for these types as:
#define PA_FOO PA_LAST #define PA_BAR (PA_LAST + 1)
Here are the flag bits that modify a basic type. They are combined with the code for the basic type using inclusive-or.
short. (This corresponds to the `h' type modifier.)
long. (This corresponds to the `l' type modifier.)
long long. (This corresponds to the `L' type modifier.)
PA_FLAG_LONG_LONG, used by convention with a base type of
PA_DOUBLEto indicate a type of
Go to the first, previous, next, last section, table of contents.