-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrefcard.tex
754 lines (661 loc) · 32.9 KB
/
refcard.tex
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
\documentclass{article}
\usepackage[a4paper, landscape, margin=1cm]{geometry}
\usepackage{fontspec}
\usepackage[french]{babel}
\usepackage[fontsize=6.5pt]{scrextend}
\usepackage[T1]{fontenc}
\usepackage{multicol}
\usepackage{tabularx}
\usepackage{sectsty}
\usepackage{lmodern}
\usepackage{stix}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\usepackage{multirow}
\usepackage{titlesec}
\usepackage{graphicx}
\input{revision}
\ifdefined\tinted
\pagecolor{Goldenrod!30}
\fi
\setlength{\parskip}{0.2em}
\setlength{\parindent}{0em}
% Highlight configuration for C programming language
\lstset{
language=c,
breaklines=true,
keywordstyle=\bfseries\color{black},
basicstyle=\ttfamily\color{black},
emphstyle={\em \color{gray}},
emph={expr, type, NAME, ptr, name, expr, value, filename, label, member, type},
mathescape=true,
keepspaces=true,
upquote=true,
showspaces=false,
showtabs=true,
tabsize=3,
escapeinside={(*}{*)}
}
% Configuration
\renewcommand{\familydefault}{\sfdefault}
\sectionfont{\fontsize{12}{15}\selectfont}
\subsectionfont{\fontsize{10}{12}\selectfont}
\subsubsectionfont{\fontsize{7}{9}\selectfont}
\allsectionsfont{\sffamily\underline}
% No pages numbering
\pagenumbering{gobble}
% Titles and paragraphs more compact
\titlespacing*{\section}{0pt}{0.5ex plus .1ex minus 0.1ex}{0.5ex plus .1ex minus 0.1ex}
\titlespacing*{\subsection}{0pt}{0.5ex plus .1ex minus 0.1ex}{0.5ex plus .1ex minus 0.1ex}
\titlespacing*{\subsubsection}{0pt}{0.5ex plus .1ex minus 0.1ex}{0.5ex plus .1ex minus 0.1ex}
\newlength\mybaselinestretch
\mybaselinestretch=0pt plus 0.02pt\relax
\addtolength{\baselineskip}{\mybaselinestretch}
\setlength\parindent{0pt}
\setlength\tabcolsep{1.5pt}
\setlength{\columnseprule}{0.4pt}
% Macros
\newcommand{\tab}{\hspace{2em}}
\newcommand{\etc}{\small \ldots}
\newcommand{\any}{$\hzigzag$~}
\newcommand{\spc}{$\mathvisiblespace$}
\newcommand{\cd}{\lstinline}
\begin{document}
\begin{multicols*}{3}
\begin{tabularx}{\columnwidth}{lX}
\raisebox{-\totalheight}{\includegraphics[width=1cm]{assets/heig-vd-black.pdf}} &
\begin{center}
{\Large \bf Carte de référence C99/C11/C18} \\
HEIG-VD -- version \revision \ -- \revisiondate \\
\end{center}
\end{tabularx}
Cette carte de référence peut être utilisée durant les travaux écrits et examens
des cours \emph{info1} et \emph{info2} à moins que le contraire soit explicitement formulé.
Elle est une liste non exhaustive des possibilités du langage C.
Les prototypes de fonction ont été volontairement simplifiés pour une meilleure lisibilité.
Signification des termes utilisés dans cette carte de référence.
\begin{tabularx}{\linewidth}{
>{\hsize=0.5\hsize}X% 10% of 4\hsize
>{\hsize=1.5\hsize}X% 30% of 4\hsize
>{\hsize=0.5\hsize}X% 30% of 4\hsize
>{\hsize=1.5\hsize}X% 30% of 4\hsize
% sum=4.0\hsize for 4 columns
}
\tt \etc & Continuation logique & \tt \any & N'importe quoi d'accepté \\
\tt /\any/ & Expression régulière & \tt \spc & Espace obligatoire \\
\cd{type} & \tt int, long, float, ... & \cd{name} & \tt /[A-Za-z][A-Za-z0-9\_]+/ \\
\cd{value} & Valeur & \cd{NAME} & \tt /[A-Z][A-Z0-9\_]+/ \\
\cd{filename} & Chemin de fichier relatif & \cd{expr} & e.g. \tt a + b \\
\end{tabularx}
\hrule
\section*{Généralités}
\begin{tabularx}{\linewidth}{lX}
Prototype de fonction & \cd{type name(type name,} \etc \cd{);} \\
Implantation de fonction & \cd{type name(type name,} \etc \cd{) \{} \any \cd{\}} \\
Déclaration de variable & \cd{type name;} \\
Fonction principale & \cd{int main(void) \{} \any \cd{\}} \\
Fonction principale avec arguments & \cd{int main(int argc, char* argv[]) \{} \any \cd{\}} \\
Valeur de retour de la fonction \texttt{main} & \cd{0} en cas de succès, \cd{!0} sinon\\
\end{tabularx}
\section*{Préprocesseur}
\begin{tabularx}{\linewidth}{Xl}
Inclure bibliothèque globale & \cd{\#include <filename>} \\
Inclure bibliothèque locale & \cd{\#include "filename"} \\
Remplacer un texte & \cd{\#define NAME expr} \\
Macro & \cd{\#define NAME(expr, ...) expr} \\
...exemple & \cd{\#define MAX(A,B) ((A)>(B) ? (A) : (B))} \\
Supprimer une définition & \cd{\#undef NAME} \\
Conversion en chaîne de caractères & \cd{\#} \\
...exemple & \cd{\#define STR(X) \#X} \\
Concaténation & \cd{\#\#} \\
Exécution conditionelle & \cd{\#if, \#else, \#elif, \#endif} \\
& \cd{\#ifdef, \#ifndef} \\
Directive pour le compilateur & \cd{\#pragma}\tt\spc \any \\
Génère une erreur de compilation & \cd{\#error}\tt\spc \any \\
Est-ce que \cd{NAME} est défini ? & \cd{defined(NAME)} \\
Saut de ligne virtuel & \cd{\\}
\end{tabularx}
\section*{Types de données}
\subsection*{Modèle de donnée}
\begin{tabularx}{\linewidth}{r|r|r|r|r|r|l|X}
\multicolumn{6}{l|}{\bf Profondeur en bits} & \bf Modèle & \bf Système d'exploitation \\
\cd {short} & \cd{int} & \cd{long} & \cd{long long} & \cd{int*} & \cd{double} & & \\
\hline
64 & 64 & 64 & 64 & 64 & & \bf \tt SILP64 & Classic UNICOS\\
16 & 32 & 64 & 64 & 64 & 64 & \bf \tt LP64 & Unix, Linux, MacOS \\
16 & 32 & 32 & 64 & 64 & & \bf \tt LLP64 & Windows x86-64, MinGW \\
16 & 32 & 32 & 64 & 32 & 64 & \bf \tt ILP32 & Windows x86 \\
16 & 16 & 32 & 64 & 32 & & \bf \tt LP32 & Certains microcontrôleurs 32-bits\\
\end{tabularx}
\subsection*{Type de base}
\begin{tabularx}{\linewidth}{X|l|l|l}
\bf Description & \bf Type standard & \bf \texttt{<stdint.h>} & \bf Profondeur \\
\hline
Caractère & \cd{char} & \cd {int8_t} & 8 bits \\
\hline
Entier & \cd{int}, \cd{signed} & \cd {int_least16_t} & $\geq$ 16 bits \\
Entier court & \cd{short} & \cd {int16_t} & $\geq$ 16 bits \\
Entier long & \cd{long} & \cd {int32_t} & $\geq$ 32 bits \\
Entier très long & \cd{long long} & \cd {int64_t} & $\geq$ 64 bits \\
Entier très long (positif) & \cd{unsigned long long} & \cd {int64_t} & $\geq$ 64 bits \\
Entier non signé (positif) & \cd{unsigned int}, \cd{unsigned} & \cd{uint_least16_t} & $\geq$ 16-bits \\
\hline
Simple précision & \cd{float} & & $\geq$ 32 bits \\
Double précision & \cd{double} & & $\geq$ 32 bits \\
%Quadruple précision & \cd{long double} & & $\geq$ 32 bits \\
\end{tabularx}
Avec \cd{<stdint.h>}, les types suivants sont disponibles, où \cd{N} est remplacé par un nombre (8, 16, 32, 64, 128), selon disponibilité par l'architecture.
\begin{tabularx}{\linewidth}{Xl}
Type fixe (p.ex. \texttt{int32\_t} & \texttt{int\textbf{N}\_t}, \texttt{uint\textbf{N}\_t} \\
Type à taille garantie (p.ex. \texttt{uint\_least8\_t}) & \texttt{int\_least\textbf{N}\_t}, \texttt{uint\_least\textbf{N}\_t} \\
Type rapide (p.ex. \texttt{int\_fast64\_t}) & \texttt{int\_fast\textbf{N}\_t}, \texttt{uint\_fast\textbf{N}\_t} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
Non défini & \cd{void} \\
Entier non signé pour comptage et indexation & \cd{size_t} \\
Entier non signé capable de stocker une adresse & \cd{uintptr_t} \\
Pointeur sur & \cd{*type} \\
Énumération & \cd{enum name \{name=value, ...\}}; \\
Structure & \cd{struct name \{type name; ... \}}; \\
Union & \cd{union name \{type name; ... \}}; \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
Type sur structure & \cd{typedef struct struct_name \{ int a; int b; \} TypeName;} \\
Structure anonyme & \cd{struct \{ int c; \} name;} \\
Structure récursive & \cd{struct Node \{ struct Node* node \} name;} \\
Liste chaînée & \cd{typedef struct element \{char *data;} \\
& \cd{\ \ struct element *next;\} element, *list, elements[5];}
\end{tabularx}
\section*{Qualificatifs de types, classes de stockage}
\begin{tabularx}{\linewidth}{X|l|l}
\bf Description & \bf Mot clé & \bf Exemple \\
\hline
Constante & \cd{const} & \cd{const char c = 'u';}\\
Déclare une variable externe & \cd{extern} & \cd{extern void func(void);}\\
Force une variable dans un registre & \cd{register} & \cd{register int i;}\\
Réduit la visiblité à ce fichier & \cd{static} & \cd{static int array[20];}\\
Pas d'optimisation pour ce symbole & \cd{volatile} & \cd{volatile int u;}\\
Limite l'aliasing d'un pointeur & \cd{restrict} & \cd{int * restrict ptr};\\
Définition de type & \cd{typedef} & \cd{typedef struct\{int a;\} Name;}\\
\end{tabularx}
\section*{Initialisation}
\begin{tabularx}{\linewidth}{Xl}
Variable & \cd{type name = value;} \\
Tableau & \cd{type name[] = \{value, ...\}}; \\
Chaîne de caractère & \cd{type name[] = "...";} \\
Stucture & \cd{type name = \{.key=value, ...\};} \\
À zéro & \cd{type name = \{0\};} \\
\end{tabularx}
\section*{Caractères non imprimables et échappements}
\begin{tabularx}{\linewidth}{
>{\hsize=0.3\hsize}X% 10% of 4\hsize
>{\hsize=0.2\hsize}X% 10% of 4\hsize
>{\hsize=1.5\hsize}X% 30% of 4\hsize
>{\hsize=0.3\hsize}X% 30% of 4\hsize
>{\hsize=0.2\hsize}X% 30% of 4\hsize
>{\hsize=1.5\hsize}X% 30% of 4\hsize
% sum=4.0\hsize for 4 columns
}
\cd{\\n} & \texttt{LF} & Nouvelle ligne & \cd{\\r} & \texttt{CR} & Retour chariot \\
\cd{\\t} & \texttt{TAB} & Tabulation horizontale & \cd{\\v} & \texttt{VT} & Tabulation verticale \\
\cd{\\f} & \texttt{FF} & Nouvelle page & \cd{\\b} & \texttt{BS} & Retour curseur (\emph{Backspace}) \\
\cd{\\0} & \texttt{NUL} & Fin de chaîne de caractère & \cd{\\a} & \texttt{BEL} & Signal sonore \\
\cd{\\x...} & & Caractère hexadécimal (\cd{\\x2a}) & \cd{\\0...} & & Caractère octal (\cd{\\030}) \rule{0pt}{3ex} \\
\cd{\\'} & & Apostrophe & \cd{\\"} & & Guillemets \\
\cd{\\?} & & Point d'interrogation & \cd{\\\\} & & Backslash \\
\end{tabularx}
\section*{Constantes littérales}
\begin{tabularx}{\linewidth}{
>{\hsize=0.4\hsize}X% 10% of 4\hsize
>{\hsize=1.5\hsize}X% 30% of 4\hsize
>{\hsize=0.6\hsize}X% 30% of 4\hsize
>{\hsize=1.5\hsize}X% 30% of 4\hsize
% sum=4.0\hsize for 4 columns
}
\cd{0xff} & Hexadécimal (\texttt{int}) & \cd{0b01100110} & Binaire\\
\cd{0012} & Octal & \cd{212} & Décimale \\
\cd{12.0f} & Simple précision (\cd{float})& \cd{12.0} & Double précision (\cd{double})\\ \hline
\cd{123u} & Entier non signé (\cd{unsigned}) & \cd{42l} & Entier \cd{long} \\
\cd{4312ll} & Entier \cd{long long} & \cd{12e-3} & Notation en E (0.012) \\ \hline
\cd{'1'} & Caractère \cd{char} (\cd{0x31}) & \cd{"abc"} & Chaîne de caractères (\cd{char*}) \\ \hline
\end{tabularx}
\subsubsection*{Suffixes (qualificatifs de type) :}
\begin{tabularx}{\linewidth}{
>{\hsize=0.5\hsize}X% 10% of 4\hsize
>{\hsize=1.1\hsize}X% 30% of 4\hsize
>{\hsize=0.9\hsize}X% 30% of 4\hsize
>{\hsize=1.5\hsize}X% 30% of 4\hsize
% sum=4.0\hsize for 4 columns
}
\cd{u} ou \cd{U} & \cd{unsigned int} & \cd{l} ou \cd{L} & \cd{long int} \\
\cd{ll} ou \cd{LL} & \cd{long long int} & \cd{ull} & \cd{unsigned long long int} \\
\end{tabularx}
\section*{Pointeurs, Tableaux et Structures}
\begin{tabularx}{\linewidth}{Xl}
Déclaration d'un pointeur & \cd{type *name;} \\
Déclaration d'un pointeur de fonction & \cd{type (*name)(type name, ...);} \\
Pointeur générique & \cd{void* name;} \\
Adresse nulle & \cd{NULL} \\
Adresse de variable & \cd{\&name} \\
Déclaration de tableau & \cd{type name[size];} \\
& \cd{type name[size][size];}, ... \\
Équivalence & \cd{a[b]}, \cd{b[a]}, \cd{*(a + b)}
\end{tabularx}
\subsection*{Structures}
\begin{tabularx}{\linewidth}{Xl}
Accès membre d'une structure & \cd{name.member}, \cd{ptr->member} \\
Accès en cas de double pointeur & \cd{(*name)->member} \\
Équivalence & \cd{(*ptr).member} et \cd{(ptr->member)} \\
Champs de bits (taille en bit) & \cd{type member : size} \\
\end{tabularx}
\section*{Opérateurs}
\begin{tabularx}{\linewidth}{c|l|X|c}
\bf Rang$\dagger$ & \bf Opérateur & \bf Description & \bf Associativité \\
\hline
\multirow{6}{*}{1} & \cd{++ --} & Suffix incrément et décrément $\ddagger$ & \multirow{6}{*}{$\rightarrow$} \\
& \cd{()} & Appel de fonction & \\
& \cd{[]} & Indice de tableau & \\
& \cd{.} & Accès à un membre de structure & \\
& \cd{->} & Identique à ci-dessus mais via pointeur & \\
& \cd{(type)\{list\}} & \emph{Compound litéral} & \\
\hline
\multirow{7}{*}{2} & \cd{++ --} & Préfixe incrément et décrément $\ddagger$ & \multirow{7}{*}{$\leftarrow$} \\
& \cd{+ -} & Plus, moins unaire (\cd{+2}, \cd{-2}) & \\
& \cd{! ~} & Négation logique et bit à bit & \\
& \cd{(type)} & Transtypage (\emph{cast}) & \\
& \cd{*} & Indirection (déréférencement) & \\
& \cd{&} & Adresse de & \\
& \cd{sizeof} & Taille de & \\
\hline
3 & \cd{* / \%} & Multiplication, division et modulo & \multirow{11}{*}{$\rightarrow$} \\
\cline{1-3}
4 & \cd{+ -} & Addition, soustraction & \\
\cline{1-3}
5 & \cd{<< >>} & Décalage à gauche, à droite & \\
\cline{1-3}
\multirow{2}{*}{6} & \cd{< <=} & Plus petit, plus petit ou égal & \\
& \cd{> >=} & Plus grand, plus grand ou égal & \\
\cline{1-3}
7 & \cd{== !=} & Égal, différent de & \\
\cline{1-3}
8 & \cd{&} & ET bit à bit & \\
\cline{1-3}
9 & \cd{^} & XOR bit à bit (ou exclusif) & \\
\cline{1-3}
10 & \cd{|} & OU bit à bit & \\
\cline{1-3}
11 & \cd{&&} & ET logique & \\
\cline{1-3}
12 & \cd{||} & OU logique & \\
\hline
13 & \cd{?:} & Opérateur ternaire & \multirow{6}{*}{$\leftarrow$} \\
\cline{1-3}
\multirow{5}{*}{14} & \cd{=} & Assignement simple & \\
& \cd{+= -=} & Assignement avec somme, différence & \\
& \cd{*= /= \%=} & Assignement avec multiplication, division, modulo & \\
& \cd{<<= >>=} & Assignement avec décalage & \\
& \cd{&= ^= |=} & Assignement avec opération bit à bit & \\
\hline
15 & \cd{,} & Virgule & $\rightarrow$\\
\end{tabularx}
$\dagger$ Plus le rang est petit, plus l'opérateur est prioritaire. \\
$\ddagger$ Opérateur est pris en compte selon priorité, mais action décalée au point de séquence suivant/précédent.
\section*{Flot de contrôle}
\begin{tabularx}{\linewidth}{
>{\hsize=1.3\hsize}X%
>{\hsize=0.7\hsize}X%
>{\hsize=1.3\hsize}X%
>{\hsize=0.7\hsize}X%
}
\multicolumn{3}{l}{Fin d'instruction (instruction vide)} & \cd{;} \\
\multicolumn{3}{l}{Délimiteur de blocs} & \cd{\{ \}} \\
\multicolumn{3}{l}{Interruption d'un \cd{switch}, \cd{do}, \cd{for}} & \cd{break} \\
\multicolumn{3}{l}{Continue à la prochaine itération d'un \cd{while}, \cd{do}, \cd{for}} & \cd{continue} \\
Saut à une étiquette & \cd{goto label} & Étiquette & \cd[emph={name}]{name:} \\
Retour de fonction & \cd{return expr;} & & \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
Si, sinon si, sinon & \cd{if (expr) \{}~\any\cd{\} else if (expr) \{}~\any\cd{\} else \{}~\any\cd{\};} \\
Tant que & \cd{while (condition de maintien) \{}~\any\cd{\}} \\
Pour & \cd{for (expr; condition de maintien; expr) \{}~\any\cd{\}} \\
Jusqu'à ce que & \cd{do \{}~\any\cd{\} while (expr);} \\
Choix multiples & \cd{switch(expr) \{ case a: instr; break; case b: instr; \}} \\
Vider le buffer & \cd{while ((c = getchar()) != '\\n' && c != EOF) \{ \}} \\
\end{tabularx}
\section*{Bibliothèques Standards}
\begin{tabularx}{\linewidth}{XXXXX}
\cd{<assert.h>} & \cd{<complex.h>} & \cd{<ctype.h>} & \cd{<errno.h>} & \cd{<fenv.h>} \\
\cd{<float.h>} & \cd{<inttypes.h>} & \cd{<limits.h>} & \cd{<locale.h>} & \cd{<math.h>} \\
\cd{<setjmp.h>} & \cd{<signal.h>} & \cd{<stdarg.h>} & \cd{<stdbool.h>} & \cd{<stddef.h>} \\
\cd{<stdint.h>} & \cd{<stdio.h>} & \cd{<stdlib.h>} & \cd{<string.h>} & \cd{<tgmath.h>} \\
\cd{<time.h>} & & & & \\
\end{tabularx}
\section*{Mots clés du langage}
\begin{tabularx}{\linewidth}{XXXXXXXX}
\cd{auto} &
\cd{break} &
\cd{case} &
\cd{char} &
\cd{const} &
\cd{continue} &
\cd{default} &
\cd{do} \\
\cd{double} &
\cd{else} &
\cd{enum} &
\cd{extern} &
\cd{float} &
\cd{for} &
\cd{goto} &
\cd{if} \\
\cd{inline} &
\cd{int} &
\cd{long} &
\cd{register} &
\cd{restrict} &
\cd{return} &
\cd{short} &
\cd{signed} \\
\cd{sizeof} &
\cd{static} &
\cd{struct} &
\cd{switch} &
\cd{typedef} &
\cd{union} &
\cd{unsigned} &
\cd{void} \\
\cd{volatile} &
\cd{while} &
\cd{_Alignas} &
\cd{_Alignof} &
\cd{_Atomic} &
\cd{_Bool} &
\cd{_Complex} &
\cd{_Generic} \\
\multicolumn{2}{l}{\cd{_Imaginary}} &
\multicolumn{2}{l}{\cd{_Noreturn}} &
\multicolumn{2}{l}{\cd{_Static_assert}} &
\multicolumn{2}{l}{\cd{_Thread_local}}
\end{tabularx}
\section*{Tests de classe de caractères \texttt{<ctype.h>}}
\begin{tabularx}{\linewidth}{X|r|l}
\bf Description & Condition & Prototype \\
\hline
Alphanumérique ? & \texttt{/[0-9a-zA-Z]/} & \cd{int isalnum(int c)} \\
Alphabétique ? & \texttt{/[a-zA-Z]/} & \cd{int isalpha(int c)} \\
Chiffre ? & \texttt{/[0-9]/} & \cd{int isdigit(int c)} \\
Caractère de contrôle ? & \footnotesize $[0\dots32, 127]$ & \cd{int iscntrl(int c)} \\
Caractère imprimable ? & \footnotesize $[33\dots 126]$ & \cd{int isgraph(int c)} \\
Caractère imprimable avec espace ? & \footnotesize$[32\dots 126]$ & \cd{int isprint(int c)} \\
Minuscule ? & \footnotesize $[97\dots 122]$ & \cd{int islower(int c)} \\
Majuscule ? & \footnotesize $[65\dots 90]$ & \cd{int isupper(int c)} \\
Espaces ? & \footnotesize $[9\dots13,32]$ & \cd{int isspace(int c)} \\
Hexadécimal ? & \texttt{/0-9a-fA-F/} & \cd{int isxdigit(int c)} \\
\multicolumn{2}{l|}{Ponctuation ? \hfill\footnotesize $[33\dots 47, 58\dots64, 91\dots96, 123\dots126]$} & \cd{int ispunct(int c)} \\
\hline
Conversion minuscule à majuscule & \texttt{/a-z/} $\to$ \texttt{/A-Z/} & \cd{int toupper(int c)} \\
Conversion majuscule à minuscule & \texttt{/A-Z/} $\to$ \texttt{/a-z/} & \cd{int tolower(int c)} \\
\end{tabularx}
\section*{Opération sur les Chaînes de caractères \texttt{<string.h>}}
\begin{tabularx}{\linewidth}{Xl}
Longueur d'une chaîne & \cd{size_t strlen(char *s)} \\
Copie \texttt{src} dans \texttt{dest} & \cd{char *strcpy(char* dest, char* src)} \\
... jusqu'à \texttt{n} caractères & \cd{char *strncpy(char* dest, char* src, size_t n)} \\
\hline
Concatène \texttt{src} après \texttt{dest} & \cd{char *strcat(char* dest, char* src)} \\
... jusqu'à \texttt{n} caractères & \cd{char *strncat(char* dest, char* src, size_t n)} \\
Compare \texttt{s1} à \texttt{s2} & \cd{int strcmp(char *s1, char *s2)} \\
... seulement \texttt{n} caractères & \cd{int strncmp(char *s1, char *s2, size_t n)} \\
\hline
Recherche premier \texttt{c} dans \texttt{str} & \cd{char *strchr(char *str, int c)} \\
Recherche dernier \texttt{c} dans \texttt{str} & \cd{char *strrchr(char *str, int c)} \\
Recherche de sous chaîne & \cd{char *strstr(char *haystack, char *needle)} \\
\hline
Copie \texttt{n} char de \texttt{s2} dans \texttt{s1} & \cd{void *memcpy(void* s1, void* s2, size_t n)} \\
Copie \texttt{n} char de \texttt{s2} dans \texttt{s1} $\dagger$ & \cd{void *memmove(void* s1, void* s2, size_t n)} \\
Cherche \texttt{c} dans \texttt{s} sur \texttt{n} char & \cd{void *memchr(void *s, int c, size_t n)} \\
Initialise \texttt{s} de longueur \texttt{n} à \texttt{c} & \cd{void *memset(void *s, int c, size_t n)} \\
Compare \texttt{n} char de \texttt{s2} avec \texttt{s1} & \cd{int memcmp(void *s1, void *s2, size_t n)} \\
\end{tabularx}
$\dagger$ Permet le chauvauchement des domaines mémoire de source et de destination.
\section*{Entrée/Sortie \texttt{<stdio.h>}}
\begin{tabularx}{\linewidth}{
>{\hsize=0.5\hsize}X% 10% of 4\hsize
>{\hsize=0.9\hsize}X% 30% of 4\hsize
>{\hsize=0.5\hsize}X% 30% of 4\hsize
>{\hsize=0.9\hsize}X% 30% of 4\hsize
>{\hsize=0.5\hsize}X% 30% of 4\hsize
>{\hsize=0.9\hsize}X% 30% of 4\hsize
}
\cd{FILE*} & Pointeur sur flux &
\cd{EOF} & Fin de fichier &
\cd{BUFSIZ} & Buffer size \\
\cd{stdin} & Entrée standard &
\cd{stdout} & Sortie standard &
\cd{stderr} & Sortie erreur \\
\cd{SEEK_SET} & Début de fichier &
\cd{SEEK_CUR} & Curseur courant &
\cd{SEEK_END} & Fin de fichier \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
Lire un caractère & \cd{int getchar(void)} \rule{0pt}{3ex} \\
Écrire un caractère & \cd{int putchar(int c)} \\
Écriture formatée & \cd{int printf(char* format, ...)} \\
Lecture formatée & \cd{int scanf(char* format, ...)} \\
Lecture dans la chaîne \texttt{s} & \cd{int sscanf(char* s, char* format, ...)} \\
Affiche la chaîne \texttt{s} & \cd{int puts(char *s)} \\
Écrire dans la chaîne \texttt{s} & \cd{int sprintf(char* s, char* format, ...)} \\
Ouvre un fichier & \cd{FILE *fopen(char* filename, char* mode)} \\
Ferme un fichier & \cd{int fclose(FILE *fp)} \\
Lire un caractère & \cd{int fgetc(FILE *fp)} \\
Écrire un caractère & \cd{int fputc(int c, FILE *fp)} \\
Position du curseur & \cd{long int ftell(FILE *fp)} \\
Déplace le curseur & \cd{int fseek(FILE *fp, long int offset, int whence)} \\
Lire une ligne & \cd{char *fgets(char* s, int n, FILE* fp)} \\
Écrire une ligne & \cd{int fputs(char* s, FILE* fp)} \\
Écriture avec format & \cd{int fprintf(FILE* fp, char* format, ...)} \\
Lecture avec format & \cd{int fscanf(FILE* fp, char* format, ...)} \\
Retourne \cd{0} si pas d'erreur & \cd{int ferror(FILE *fp)} \\
Retourne \cd{!0} si fin de fichier & \cd{int feof(FILE *fp)} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
Lecture & \cd{size_t fread(void *p, size_t size, size_t n, FILE *fp)} \\
Écriture & \cd{size_t fwrite(void *p, size_t size, size_t n, FILE *fp)} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{
>{\hsize=0.2\hsize}X >{\hsize=1.8\hsize}X
>{\hsize=0.2\hsize}X >{\hsize=1.8\hsize}X
>{\hsize=0.2\hsize}X >{\hsize=1.8\hsize}X
}
\multicolumn{4}{l}{\bf Modes d'ouverture de fichiers (\cd{/"[rwa]b?\\+?"/})} \\
\tt r & Lecture & \tt w & Écriture & \tt a & Ajout \\
\tt b & \multicolumn{5}{l}{Mode binaire, les \textbf{LF} (\cd{\\n}) sont converti en \textbf{CRLF} (\cd{\\r\\n}) sous Windows} \\
\tt + & \multicolumn{5}{l}{Mode lecture/écriture le fichier peut être écrit et lu} \\
\end{tabularx}
Les options \cd{w+}, \cd{wb+} et \cd{w} créent le fichier si inexistant ou l'efface s'il existe. \\
Ne pas oublier que
le mode est une chaîne de caractère (p.ex. \cd{"rb+"}, pas \cd{'rb+'}). \\
\subsection*{Formattage de chaîne de caractères}
Format pour \texttt{printf}: \texttt{\%[flags][width|*][.precision|*][length]type} \\
Format pour \texttt{scanf}: \texttt{\%[*][width][length]type} \\
\texttt{*}: Taille passée en argument (printf), Supprime la capture (scanf)
\begin{tabularx}{\linewidth}{
>{\hsize=0.2\hsize}X>{\hsize=1.8\hsize}X
>{\hsize=0.2\hsize}X>{\hsize=1.8\hsize}X
}
\multicolumn{4}{l}{\bf Drapeaux (\texttt{flags})} \\
\cd{-} & Justifie à gauche & \cd{+} & Affiche le signe \texttt{+} \\
\tt \spc & Remplissage avec des espace (défaut) & \cd{0} & Remplissage avec des zéros \\
\end{tabularx}
\begin{tabularx}{\linewidth}{
>{\hsize=0.2\hsize}X>{\hsize=1.8\hsize}X
>{\hsize=0.2\hsize}X>{\hsize=1.8\hsize}X
}
\multicolumn{4}{l}{\bf Longueur (\texttt{length})} \\
\cd{hh} & Entier promu d'un \cd{char} & \cd{h} & Entier promu d'un \cd{short} \\
\cd{ll} & Entier \cd{long long} & \cd{l} & Entier \cd{long} \\
\cd{L} & Flottant double précision & \cd{z} & Entier \cd{size_t} \\
\cd{j} & Entier \cd{intmax_t} & \cd{t} & Entier \cd{ptrdiff_t} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{
>{\hsize=0.2\hsize}X% 10% of 4\hsize
>{\hsize=1.8\hsize}X% 30% of 4\hsize
>{\hsize=0.2\hsize}X% 30% of 4\hsize
>{\hsize=1.8\hsize}X% 30% of 4\hsize
% sum=4.0\hsize for 4 columns
}
\multicolumn{4}{l}{\bf Champ type (\texttt{type})} \\
\cd{\%} & Caractère pourcent & \cd{c} & Caractère (\texttt{char}) \\
\cd{d}, \cd{i} & Entier signé & \cd{u} & Entier non signé \\
\cd{o} & Entier non signé en octal & \cd{x}, \cd{X} & Entier non signé en hexadécimal \\
\cd{f}, \cd{F} & \cd{float} et \cd{double} (\cd{\%lf} avec \cd{scanf}) & \cd{a}, \cd{A} & Double en hexadécimal \\
\cd{p} & Pointeur (adresse) & \cd{n} & Nombre de caractère écrits \\
\cd{zu} & Valeur \cd{size_t} & \cd{[]} & Liste de capture (\cd{[aeX]}, \cd{[^\\n]}) \\
\cd{e}, \cd{E} & \multicolumn{3}{l}{Double en format exponentiel \texttt{[-]d.ddd e [+-]ddd}}\\
\cd{g}, \cd{G} & \multicolumn{3}{l}{Double en format le plus adapté normal (\cd{f}, \cd{F}) ou exponentiel (\cd{e}, \cd{E})} \\
\cd{s} & \multicolumn{3}{l}{Chaîne de caractère (jusqu'à \cd{EOL} pour \cd{printf} ou un espace pour \cd{scanf})}
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
\multicolumn{2}{l}{\bf Exemples pour \cd{scanf}} \\
Consomme jusqu'à la prochaine fin de ligne & \cd{scanf("\%*[^\\n]\%*[\\n]")} \\
Capture seulement une voyelle & \cd{scanf("\%[aeiouy]", \&name)} \\
\end{tabularx}
\section*{Utilitaires Standard \texttt{<stdlib.h>}}
\begin{tabularx}{\linewidth}{Xl}
\multicolumn{2}{l}{\bf Macros} \\
Code de fin pour \cd{exit()} indiquant un succès & \cd{EXIT_SUCCESS} \\
Code de fin pour \cd{exit()} indiquant une erreur & \cd{EXIT_FAILURE} \\
Pointeur null & \cd{NULL} \\
Valeur aléatoire maximum ($>=32767$) & \cd{RAND_MAX} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{
>{\hsize=0.2\hsize}X% 10% of 4\hsize
>{\hsize=1.8\hsize}X% 30% of 4\hsize
>{\hsize=0.2\hsize}X% 30% of 4\hsize
>{\hsize=1.8\hsize}X% 30% of 4\hsize
% sum=4.0\hsize for 4 columns
}
\multicolumn{4}{l}{\bf Suffix pour fonctions \cd{ato}\texttt{\spc} et \cd{strto}\texttt{\spc}} \\
\cd{f} & \cd{float} & \cd{d} & \cd{double} \\
\cd{i} & \cd{int} & \cd{l} & \cd{long} \\
\cd{ll} & \cd{long long} & \cd{ld} & \cd{long double} \\
\cd{ul} & \cd{unsigned long} & \cd{ull} & \cd{unsigned long long} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
\multicolumn{2}{l}{\bf Conversion de chaînes de caractères en nombre} \\
\cd{f}, \cd{i}, \cd{l}, \cd{ll} & \cd{type ato}\texttt{\spc}\cd{ (char* str);} \\
\cd{f}, \cd{l}, \cd{d}, \cd{ld}, \cd{ll}, \cd{ul}, \cd{ull} & \cd{type strto}\texttt{\spc}\cd{ (char* str, char** endptr);} \\
\multicolumn{2}{l}{\bf Arithmétique d'entiers} \rule{0pt}{3ex}\\
Valeur absolue & \cd{int abs (int n);} \\
Valeur absolue long & \cd{long labs (long n);} \\
Valeur absolue long long & \cd{long long llabs (long long n);} \\
Division entière & \cd{int div (int n);} \\
Division entière long & \cd{long ldiv (long n);} \\
Division entière long long & \cd{long long lldiv (long long n);} \\
\multicolumn{2}{l}{\bf Pseudo aléatoire} \rule{0pt}{3ex}\\
Nombre aléatoire \cd{[0,RAND_MAX]} & \cd{int rand (void);} \\
Initialise le générateur aléatoire & \cd{void srand (unsigned int seed);} \\
\multicolumn{2}{l}{\bf Environement} \rule{0pt}{3ex}\\
Termine le processus & \cd{void exit (int status);} \\
Termine le processus avec \cd{SIGABRT} & \cd{void abort(void);} \\
Exécute une commande système & \cd{int system (const char* command);} \\
Récupère l'environment & \cd{char* getenv (const char* name);} \\
\multicolumn{2}{l}{\bf Allocation de mémoire dynamique} \rule{0pt}{3ex} \\
Alloue un tableau initialisé & \cd{void* calloc (size_t num, size_t size);} \\
Alloue un bloc mémoire & \cd{void* malloc (size_t size);} \\
Réalloue un bloc mémoire & \cd{void* realloc (void* ptr, size_t size);} \\
Désalloue un bloc mémoire & \cd{void free (void* ptr);} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
\multicolumn{2}{l}{\bf Tri et recherche} \rule{0pt}{3ex} \\
Recherche dichotomique & \cd{void* bsearch (void* key, void* base, size_t num,} \\
& \cd{\ \ \ \ size_t size, int (*compar)(void*, void*));} \\
Tri rapide & \cd{void qsort (void* base, size_t num,} \\
& \cd{\ \ \ \ size_t size, int (*compar)(void*, void*));} \\
\end{tabularx}
\section*{Date et heure \texttt{<time.h>}}
\begin{tabularx}{\linewidth}{Xl}
Temps absolu en seconde depuis 1970/01/01 & \cd{time_t} \\
Temps relatif depuis un point dans le temps (\emph{boot}) & \cd{clock_t} \\
Temps calendrier (date et heure) & \cd{struct tm} \\
\end{tabularx}
\begin{tabularx}{\linewidth}{Xl}
Temps écoulé depuis le début & \cd{clock_t clock(void)} \\
Temps calendrier courante & \cd{time_t time(time_t *timer)} \\
Différence de temps en secondes & \cd{double difftime(time_t time1, time_t time2)} \\
Conversion en temps calendrier & \cd{time_t mktime(struct tm *timeptr)} \\
Conversion d'un temps calendrier & \cd{struct tm *gmtime(const time_t *timer)} \\
Conversion d'un temps locale & \cd{struct tm *localtime(const time_t *timer)} \\
Représentation texte & \cd{char *asctime(const struct tm *timeptr)} \\
Représentation texte & \cd{char *ctime(const time_t *timer)} \\
Gabarit d'un temps & \cd{size_t strftime(char *str, size_t maxsize,} \\
& \cd{\ \ \ \ char *format, struct tm *timeptr)} \\
\end{tabularx}
{
\small
\begin{lstlisting}
struct tm {
int tm_sec; // Secondes (0..59)
int tm_min; // Minutes (0..59)
int tm_hour; // Heures (0..23)
int tm_mday; // Jour du mois (1..31)
int tm_mon; // Mois (0..11)
int tm_year; // Nombre d'années depuis 1900
int tm_wday; // Jour depuis dimanche (0..6)
int tm_yday; // Jour dans l'année de (0..365)
int tm_isdst; // Heure été ? (Daylight Saving Time)
};
\end{lstlisting}
}
Format pour \texttt{asctime}: \cd{"\%.3s \%.3s\%3d \%.2d:\%.2d:\%.2d \%d\\n"}
\section*{Fonctions Mathématique \texttt{<math.h>}}
Si non spécifé, le prototype est la forme \cd{double func(double x)}.
\begin{tabularx}{\linewidth}{Xl}
Fonctions trigonométriques & \cd{cos}, \cd{sin}, \cd{tan} \\
Fonctions inverses (\emph{arc}) & \cd{acos}, \cd{asin}, \cd{atan} \\
Fonctions hyperbliques & \cd{cosh}, \cd{sinh}, \cd{tanh} \\
Arctangente corrigée $\arctan(y / x)$ & \cd{double atan2(double y, double x)} \\
Fonctions exponentielles & \cd{exp}, \cd{log}, \cd{log10} \\
Division (retourne partie décimale) & \cd{double modf(double x, double *integer)} \\
Reste de division $x/y$ pour $x - n \cdot y$ & \cd{double fmod(double x, double y)} \\
Arrondi à l'entier inférieur & \cd{floor} \\
Arrondi à l'entier supérieur & \cd{ceil} \\
Valeur absolue & \cd{fabs} \\
Puissance & \cd{double pow(double x, double y)} \\
Racine carrée & \cd{sqrt} \\
\end{tabularx}
\section*{Booléens \texttt{<stdbool.h>}}
\cd{bool}, \cd{true} (vrai (1)), \cd{false} (faux (0)) \\
\cd{assert(0 == !1 && !1 == 0 && !!12345 == 1)}
\section*{Limites \texttt{<limits.h>} / \texttt{<float.h>}}
Valeurs typiques pour un modèle de donnée \textbf{LP32}.
\begin{tabularx}{\linewidth}{
>{\hsize=0.9\hsize}X% 10% of 4\hsize
>{\hsize=1.2\hsize}X% 30% of 4\hsize
>{\hsize=0.9\hsize}X% 30% of 4\hsize
>{\hsize=1.2\hsize}X% 30% of 4\hsize
% sum=4.0\hsize for 4 columns
}
\cd{CHAR_BIT} & (8) & & \\
\cd{SCHAR_MAX} & +127 & \cd{SCHAR_MIN} & -128 \\
\cd{CHAR_MAX} & \cd{SCHAR_MAX} & \cd{CHAR_MIN} & \cd{SCHAR_MIN} \\
\cd{SHRT_MAX} & +32'767 & \cd{SHRT_MIN} & -32'768 \\
\cd{INT_MAX} & +2'147'483'647 & \cd{INT_MIN} & -2'147'483'648 \\
\cd{LONG_MAX} & +2'147'483'647 & \cd{LONG_MIN} & -2'147'483'648 \\
\cd{LLONG_MAX} & +2e63 - 1 & \cd{LLONG_MIN} & -2e63 \\
\cd{UCHAR_MAX} & +255 & \cd{UINT_MAX} & +4'294'967'295 \\
\cd{ULONG_MAX} & +4'294'967'295 & \cd{ULLONG_MAX} & +2e64 - 1 \\
\cd{FLT_MAX} & \cd{3.4e38} & \cd{FLT_MIN} & \cd{1.2e-38} \\
\cd{DBL_MAX} & \cd{1.8e308} & \cd{DBL_MIN} & \cd{2.2e-308} \\
\cd{FLT_EPSILON} & \cd{1.1e-7} & \cd{DBL_EPSILON} & \cd{2.2e-16}
\end{tabularx}
% \section*{Compilation (gcc/clang)}
% \begin{tabularx}{\linewidth}{Xl}
% \texttt{-O2 -std=c99 -Wall -Wextra -Wconversion} & Options standards \\
% \texttt{-g} & Débug \\
% \texttt{cc filename.c} & Compilation simple \\
% \texttt{cc -o name filename.c} & Compilation simple, \\
% & choix du nom de l'exécutable \\
% \end{tabularx}
\end{multicols*}
\end{document}