-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabout_printf.txt
327 lines (285 loc) · 7.01 KB
/
about_printf.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# **************************************************************************** #
# #
# ::: :::::::: #
# printf_and_how_it_works.txt :+: :+: :+: #
# +:+ +:+ +:+ #
# By: amalsago <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/02/20 09:53:38 by amalsago #+# #+# #
# Updated: 2019/05/20 16:31:23 by amalsago ### ########.fr #
# #
# **************************************************************************** #
The format-string consist of:
ordinary characters - they are copied in order of ther appearance
escape sequences -
conversion specifications - they begins with %
Placeholder syntax:
%[parameter$][flags][width][.precision][length]type
type
c Character
s String of character
p Pointer address
d Signed decimal integer
i Signed decimal integer
o Unsigned octal
u Unsigned decimal integer
x Unsigned hexadecimal integer (lowercase)
X Unsigned hexadecimal integer (upperrcase)
f Decimal floating point (lowercase)
If % is followed by a character that has no meaning as a format field,
the character is simply copied to stdout. For example %%
[parameter] POSIX extension and not in C99, so can be omitted.
n$ 'n' is the number of the parameter to display. If any placeholder
specifies a parameter, all the rest of the placeholder MUST specify
a paramater number. Or behavior is undefined.
[flags] The flags can be zero or more (in any order)
'-' Left-justify (instead default right)
'+' For signed %d and %i conversions,print a plus sign.
' ' Insert blank space for %d and %i conversions, instead plus sign
Ingored when flag '+' is present
'0' Left-pads the number with zeroes when [width] is specified
only for d, i, o, u, x, X, e, E, f, g and G conversions
Ignored if '-' is specified.
Ignored for (i, u, x, X, o, d) if only '.' or '.0' is specified
'#' For o, x and X preceeed with 0, 0x and 0X respectively to any nonzero output
For f force to write a decimal point even if no more digits follow.
Shouldn't be use with c, d, i, u, s and p conversion specifier.
[width] Minimum number of characters to print. If the number of characters
in the output is less than the specified [width], black are added on
the left or the rigth (depending if '-' flag is specified).
If the number of characters in the output value is greater that
specified [width] or [width] is not given, all the characters of the
value are printed
The [width] can ne an *, so an argument from argument list is used.
If format-string contains [parameter], [width] cat be indicated by
the sequence `*m$`, where m is a decimal integer in the range of
arguments.
[.precision] Specify the number of characters to print or the number of decimal places.
The precision can cause truncation of the output value or rounding of a
floating-point value.
only '.' disable flag '0'
[length] Modifies the length of the data type
'h' Convert to short???
'hh' Convert to char???
'l'
'll'
'L' Convert to long double???
Char/String
c Char
s String
p Poiner
Number
SIGNED
di Signed decimal
f Decimal floating point
UNSIGNED
u Unsigned decimal
o Unsigned octal
xX Unsigned hexadecimal
___
csp
---
%c
'-'
'+' undefined behavior but print
' ' undefined behavior but print
'0' undefined behavior but print and adds 0 if width is specified
'#' undefined behavior but print
[width]
[precision] undefined behavior but print
%s
'-'
'+' Deactivate; undefined behavior but print
' ' Deactivate; undefined behavior but print
'0' Deactivate; undefined behavior but print
If width > data.length padded with 0's on left instead spaces
'#' Отключить; undefined behavior but print
[width]
[precision] Максимальное число символов, которые будут выведены
Если [точность] > длина строки, вывести все символы строки
Если после '.' не указано значение, то не выводить строку
%p
'-'
'+' undefined behavior but print
' ' undefined behavior but print
'0' undefined behavior but print
'#' undefined behavior but print
[width]
[precision] add at the left after 0x if precision is > thant number of digits
______
diouxX
------
%d %i
'-'
'+'
' '
'0'
'#' undefined behavior but print
[width]
[precision] add '0' at the left if precision is > thant number of digits
%o
'-'
'+' undefined behavior but print
' ' undefined behavior but print
'0'
'#'
[width] add '0' at the left if width > nb of digits
[precision] add '0' at the left
if [precision] is only '.' print just number
%u
If number < 0 prints garbage value
'-'
'+' undefined behavior but print
' ' undefined behavior but print
'0' undefined behavior but print
'#' undefined behavior but print
[width]
[precision] add at the left after 0x if precision is > thant number of digits
%x
'-'
'+' undefined behavior but print
' ' undefined behavior but print
'0'
'#'
[width]
[precision] add at the left after 0x if precision is > thant number of digits
___
%f
---
'-'
'+'
' '
'0'
'#' writing just float
[width] filling with `0` if [width] > of nb of digits of number
[precision] if [precisin] is only '.' write only integr part and rounding
1. Unsed argument
printf("Hello ", "world");
Warning: data argumet not used by format string
2. Not enough arguments
printf("Hello %s");
Warning: more '%' conversions than data arguments
--------------------------------------------------------------------------------
iMac 27-inch, Late 2012
macOS Sierra 10.12.6 (16G29)
Processor 2,9 GHz Intel Core i5
Memory 8 GB 1600 MHz DDR3
________________________________________________________________________________
GCC OPTIMISATION OPTIONS DIFFERENCE
LIBFT FT_PRINTF Size
110760
-Ofast 100064
-Ofast 106024
-Ofast -Ofast 95328
-O2 -O2 95304
=== Ofast ===
116
116
118
138
128
118
118
118
123
122
118
119
113
110
123
122
121
114
124
=== O2 ===
129
124
128
116
117
115
122
124
118
126
120
114
121
120
122
117
137
126
121
118
117
122
122
123
115
125
123
117
121
121
130
122
120
122
124
123
124
119
124
121
121
117
= 121%
MacBook Pro Retina, 13-inch, Early 2015
macOS Sierra 10.12.6 (16G1918)
Processor 3,1 GHz Intel Core i7
Memory 16 GB 1867 MHz DDR3
133
133
130
134
134
150
132
134
140
135
138
134
114
134
131
134
135
142
128
133
134
165
121
137
130
203
103
131
137
133
146
136
134
130
126
120
130
134
135
131
132
256
= 137%