The GNU C Library - Registering New Conversions

Node: Registering New Conversions Next: Conversion Specifier Options Up: Customizing Printf

Registering New Conversions

The function to register a new output conversion is register_printf_function , declared in `printf.h'.

Function int register_printf_function (int spec, printf_function handler-function, printf_arginfo_function arginfo-function)
This function defines the conversion specifier character spec. Thus, if spec is 'q' , it defines the conversion `%q'.

The handler-function is the function called by printf and friends when this conversion appears in a template string. See Defining the Output Handler, for information about how to define a function to pass as this argument. If you specify a null pointer, any existing handler function for spec is removed.

The arginfo-function is the function called by parse_printf_format when this conversion appears in a template string. See Parsing a Template String, for information about this.

Normally, you install both functions for a conversion at the same time, but if you are never going to call parse_printf_format , you do not need to define an arginfo function.

The return value is 0 on success, and -1 on failure (which occurs if spec is out of range).

You can redefine the standard output conversions, but this is probably not a good idea because of the potential for confusion. Library routines written by other people could break if you do this.


Next: Conversion Specifier Options Up: Customizing Printf