Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Printf
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Custom data type formatting === A common way to handle formatting with a custom data type is to format the custom data type value into a [[string (computer science)|string]], then use the {{code|%s|c}} specifier to include the serialized value in a larger message. Some printf-like functions allow extensions to the [[escape-character]]-based [[mini-language]], thus allowing the programmer to use a specific formatting function for non-builtin types. One is the (now [[deprecated]]) [[glibc]]'s [https://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html {{code|register_printf_function()}}]. However, it is rarely used due to the fact that it conflicts with [[static program analysis|static format string checking]]. Another is [http://www.and.org/vstr/#cust-fmt Vstr custom formatters], which allows adding multi-character format names. Some applications (like the [[Apache HTTP Server]]) include their own printf-like function, and embed extensions into it. However these all tend to have the same problems that {{code|register_printf_function()}} has. The [[Linux kernel]] <code>[[printk]]</code> function supports a number of ways to display kernel structures using the generic {{code|%p|c}} specification, by {{em|appending}} additional format characters.<ref>{{cite web | url= https://docs.kernel.org/core-api/printk-formats.html | title= How to get printk format specifiers right | work = The Linux Kernel documentation | first1= Randy | last1= Dunlap | first2= Andrew | last2= Murray | publisher= [[Linux Foundation]] | date= n.d. | access-date= 2025-02-12 | archive-date= 2025-02-06 | archive-url= https://web.archive.org/web/20250206200419/https://docs.kernel.org/core-api/printk-formats.html | url-status= live }}</ref> For example, {{code|%pI4|c}} prints an [[IPv4 address]] in dotted-decimal form. This allows static format string checking (of the {{code|%p|c}} portion) at the expense of full compatibility with normal printf.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)