Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdio/printf.3
Show All 25 Lines | |||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
.\" | .\" | ||||
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93 | .\" @(#)printf.3 8.1 (Berkeley) 6/4/93 | ||||
.\" | .\" | ||||
.Dd May 22, 2018 | .Dd August 21, 2023 | ||||
.Dt PRINTF 3 | .Dt PRINTF 3 | ||||
.Os | .Os | ||||
.Sh NAME | .Sh NAME | ||||
.Nm printf , | .Nm printf , | ||||
.Nm fprintf , | .Nm fprintf , | ||||
.Nm sprintf , | .Nm sprintf , | ||||
.Nm snprintf , | .Nm snprintf , | ||||
.Nm asprintf , | .Nm asprintf , | ||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | |||||
The value should be converted to an | The value should be converted to an | ||||
.Dq alternate form . | .Dq alternate form . | ||||
For | For | ||||
.Cm c , d , i , n , p , s , | .Cm c , d , i , n , p , s , | ||||
and | and | ||||
.Cm u | .Cm u | ||||
conversions, this option has no effect. | conversions, this option has no effect. | ||||
For | For | ||||
.Cm b | |||||
and | |||||
.Cm B | |||||
conversions, a non-zero result has the string | |||||
.Ql 0b | |||||
(or | |||||
.Ql 0B | |||||
for | |||||
.Cm B | |||||
conversions) prepended to it. | |||||
For | |||||
.Cm o | .Cm o | ||||
conversions, the precision of the number is increased to force the first | conversions, the precision of the number is increased to force the first | ||||
character of the output string to a zero. | character of the output string to a zero. | ||||
For | For | ||||
.Cm x | .Cm x | ||||
and | and | ||||
.Cm X | .Cm X | ||||
conversions, a non-zero result has the string | conversions, a non-zero result has the string | ||||
Show All 17 Lines | |||||
conversions, trailing zeros are not removed from the result as they | conversions, trailing zeros are not removed from the result as they | ||||
would otherwise be. | would otherwise be. | ||||
.It So Cm 0 Sc (zero) | .It So Cm 0 Sc (zero) | ||||
Zero padding. | Zero padding. | ||||
For all conversions except | For all conversions except | ||||
.Cm n , | .Cm n , | ||||
the converted value is padded on the left with zeros rather than blanks. | the converted value is padded on the left with zeros rather than blanks. | ||||
If a precision is given with a numeric conversion | If a precision is given with a numeric conversion | ||||
.Cm ( d , i , o , u , i , x , | .Cm ( b , B , d , i , o , u , i , x , | ||||
and | and | ||||
.Cm X ) , | .Cm X ) , | ||||
the | the | ||||
.Cm 0 | .Cm 0 | ||||
flag is ignored. | flag is ignored. | ||||
.It Sq Cm \- | .It Sq Cm \- | ||||
A negative field width flag; | A negative field width flag; | ||||
the converted value is to be left adjusted on the field boundary. | the converted value is to be left adjusted on the field boundary. | ||||
Show All 39 Lines | |||||
the field width. | the field width. | ||||
.It | .It | ||||
An optional precision, in the form of a period | An optional precision, in the form of a period | ||||
.Cm \&. | .Cm \&. | ||||
followed by an | followed by an | ||||
optional digit string. | optional digit string. | ||||
If the digit string is omitted, the precision is taken as zero. | If the digit string is omitted, the precision is taken as zero. | ||||
This gives the minimum number of digits to appear for | This gives the minimum number of digits to appear for | ||||
.Cm d , i , o , u , x , | .Cm b , B , d , i , o , u , x , | ||||
and | and | ||||
.Cm X | .Cm X | ||||
conversions, the number of digits to appear after the decimal-point for | conversions, the number of digits to appear after the decimal-point for | ||||
.Cm a , A , e , E , f , | .Cm a , A , e , E , f , | ||||
and | and | ||||
.Cm F | .Cm F | ||||
conversions, the maximum number of significant digits for | conversions, the maximum number of significant digits for | ||||
.Cm g | .Cm g | ||||
and | and | ||||
.Cm G | .Cm G | ||||
conversions, or the maximum number of characters to be printed from a | conversions, or the maximum number of characters to be printed from a | ||||
string for | string for | ||||
.Cm s | .Cm s | ||||
conversions. | conversions. | ||||
.It | .It | ||||
An optional length modifier, that specifies the size of the argument. | An optional length modifier, that specifies the size of the argument. | ||||
The following length modifiers are valid for the | The following length modifiers are valid for the | ||||
.Cm d , i , n , o , u , x , | .Cm b , B , d , i , n , o , u , x , | ||||
or | or | ||||
.Cm X | .Cm X | ||||
conversion: | conversion: | ||||
.Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *" | .Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *" | ||||
.It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n | .It Sy Modifier Ta Cm d , i Ta Cm b , B , o , u , x , X Ta Cm n | ||||
.It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *" | .It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *" | ||||
.It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *" | .It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *" | ||||
.It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *" | .It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *" | ||||
.It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *" | .It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *" | ||||
.It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *" | .It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *" | ||||
.It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *" | .It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *" | ||||
.It Cm z Ta (see note) Ta Vt size_t Ta (see note) | .It Cm z Ta (see note) Ta Vt size_t Ta (see note) | ||||
.It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *" | .It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *" | ||||
.El | .El | ||||
.Pp | .Pp | ||||
Note: | Note: | ||||
the | the | ||||
.Cm t | .Cm t | ||||
modifier, when applied to a | modifier, when applied to a | ||||
.Cm o , u , x , | .Cm b , B , o , u , x , | ||||
or | or | ||||
.Cm X | .Cm X | ||||
conversion, indicates that the argument is of an unsigned type | conversion, indicates that the argument is of an unsigned type | ||||
equivalent in size to a | equivalent in size to a | ||||
.Vt ptrdiff_t . | .Vt ptrdiff_t . | ||||
The | The | ||||
.Cm z | .Cm z | ||||
modifier, when applied to a | modifier, when applied to a | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
A negative field width is treated as a left adjustment flag followed by a | A negative field width is treated as a left adjustment flag followed by a | ||||
positive field width; a negative precision is treated as though it were | positive field width; a negative precision is treated as though it were | ||||
missing. | missing. | ||||
If a single format directive mixes positional | If a single format directive mixes positional | ||||
.Pq Li nn$ | .Pq Li nn$ | ||||
and non-positional arguments, the results are undefined. | and non-positional arguments, the results are undefined. | ||||
.Pp | .Pp | ||||
The conversion specifiers and their meanings are: | The conversion specifiers and their meanings are: | ||||
.Bl -tag -width ".Cm diouxX" | .Bl -tag -width ".Cm bBdiouxX" | ||||
.It Cm diouxX | .It Cm bBdiouxX | ||||
The | The | ||||
.Vt int | .Vt int | ||||
(or appropriate variant) argument is converted to signed decimal | (or appropriate variant) argument is converted to | ||||
unsigned binary | |||||
.Cm ( b | |||||
and | |||||
.Cm B ) , | |||||
signed decimal | |||||
.Cm ( d | .Cm ( d | ||||
debdrup: Why the newline here? | |||||
Done Inline Actionsit makes no difference for the output but makes the source more readable as each element in the enumeration has the same form. des: it makes no difference for the output but makes the source more readable as each element in the… | |||||
Not Done Inline Actionsigor complains about blank lines though emaste: igor complains about blank lines though | |||||
Done Inline Actionswhere? des: where? | |||||
and | and | ||||
.Cm i ) , | .Cm i ) , | ||||
unsigned octal | unsigned octal | ||||
.Pq Cm o , | .Pq Cm o , | ||||
unsigned decimal | unsigned decimal | ||||
.Pq Cm u , | .Pq Cm u , | ||||
or unsigned hexadecimal | or unsigned hexadecimal | ||||
.Cm ( x | .Cm ( x | ||||
▲ Show 20 Lines • Show All 501 Lines • Show Last 20 Lines |
Why the newline here?