update
[tinycc.git] / tcc-doc.texi
blob4347fb17a90b346a90496197542ba2cd6eea04ea
1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2 <html>
3 <head>
4    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5    <title> Tiny C Compiler Reference Documentation </title>
6 </head>
7 <body>
9 <center>
10 <h1>
11 Tiny C Compiler Reference Documentation
12 </h1>
13 </center>
15 <h2>Introduction</h2>
17 TinyCC (aka TCC) is a small but very fast C compiler. Unlike other C
18 compilers, it is meant to be self-suffisant: you do not need an
19 external assembler or linker because TCC does that for you.
20 <P>
22 TCC compiles so fast that even for big projects <tt>Makefile</tt>s may
23 not be necessary. 
24 <P>
25 TCC can also be used to make <I>C scripts</I>,
26 i.e. pieces of C source that you run as a Perl or Python
27 script. Compilation is so fast that your script will be as fast as if
28 it was an executable.
30 <h2>Exact differences with ANSI C</h2>
32 TCC implements almost all the ANSI C standard, except floating points
33 numbers.
35 <ul>
36  <li> The preprocessor tokens are the same as C. It means that in some
37   rare cases, preprocessed numbers are not handled exactly as in ANSI
38   C. This approach has the advantage of being simpler and FAST!
40  <li> Floating point numbers are not fully supported yet (some
41  implicit casts are missing).
43  <li> Some typing errors are not signaled.
44 </ul>
46 <h2>ISOC99 extensions</h2>
48 TCC implements many features of the new C standard: ISO C99. Currently
49 missing items are: complex and imaginary numbers (will come with ANSI
50 C floating point numbers), <tt>long long</tt>s and variable length
51 arrays.
53 Currently implemented ISOC99 features:
55 <ul>
57 <li> <tt>'inline'</tt> keyword is ignored.
59 <li> <tt>'restrict'</tt> keyword is ignored.
61 <li> <tt>'__func__'</tt> is a string variable containing the current
62 function name.
64 <li> Variadic macros: <tt>__VA_ARGS__</tt> can be used for
65    function-like macros:
66 <PRE>
67     #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__)
68 </PRE>
69 <tt>dprintf</tt> can then be used with a variable number of parameters.
71 <li> Declarations can appear anywhere in a block as in C++.
73 <li> Array and struct/union elements can be initialized in any order by
74   using designators:
75 <PRE>
76     struct { int x, y; } st[10] = { [0].x = 1, [0].y = 2 };
78     int tab[10] = { 1, 2, [5] = 5, [9] = 9};
79 </PRE>
80     
81 <li> Compound initializers are supported:
82 <PRE>
83     int *p = (int []){ 1, 2, 3 };
84 </PRE>
85 to initialize a pointer pointing to an initialized array. The same
86 works for structures and strings.
88 <li> The boolean type <tt>'_Bool'</tt> is supported.
90 <li> <tt>'long long'</tt> types not supported yet, except in type
91  definition or <tt>'sizeof'</tt>.
93 <li> Hexadecimal floating point constants are supported:
94 <PRE>
95           double d = 0x1234p10;
96 </PRE>
97 is the same as writing 
98 <PRE>
99           double d = 4771840.0;
100 </PRE>
101 </ul>
103 <h2>GNU C extensions</h2>
105 TCC implements some GNU C extensions which are found in many C sources:
107 <ul>
109 <li> array designators can be used without '=': 
110 <PRE>
111     int a[10] = { [0] 1, [5] 2, 3, 4 };
112 </PRE>
114 <li> Structure field designators can be a label: 
115 <PRE>
116     struct { int x, y; } st = { x: 1, y: 1};
117 </PRE>
118 instead of
119 <PRE>
120     struct { int x, y; } st = { .x = 1, .y = 1};
121 </PRE>
123 <li> <tt>'\e'</tt> is ASCII character 27.
125 </ul>
127 <h2>TinyCC extensions</h2>
129 I have added some extensions I find interesting:
131 <ul>
133 <li> <tt>__TINYC__</tt> is a predefined macro to <tt>'1'</tt> to
134 indicate that you use TCC.
136 <li> <tt>'#!'</tt> at the start of a line is ignored to allow scripting.
138 <li> Binary digits can be entered (<tt>'0b101'</tt> instead of
139 <tt>'5'</tt>).
141 </ul>
143 <h2> Command line invokation </h2>
145 <PRE>
146 usage: tcc [-Idir] [-Dsym] [-llib] [-i infile] infile [infile_args...]
147 </PRE>
149 <table>
150 <tr><td>'-Idir'</td> 
151 <td>specify an additionnal include path. The default ones are:
152 /usr/include, /usr/lib/tcc, /usr/local/lib/tcc.</td>
154 <tr><td>'-Dsym'</td>
155 <td>define preprocessor symbol 'sym' to 1.</td>
157 <tr><td>'-lxxx'</td>
158 <td>dynamically link your program with library
159 libxxx.so. Standard library paths are checked, including those
160 specificed with LD_LIBRARY_PATH.</td>
162 <tr><td>'-i file'</td>
163 <td>compile C source 'file' before main C source. With this
164 command, multiple C files can be compiled and linked together.</td>
165 </table>
167 <hr>
168 Copyright (c) 2001 Fabrice Bellard <hr>
169 Fabrice Bellard - <em> fabrice.bellard at free.fr </em> - <A HREF="http://fabrice.bellard.free.fr/"> http://fabrice.bellard.free.fr/ </A> - <A HREF="http://www.tinycc.org/"> http://www.tinycc.org/ </A>
171 </body>
172 </html>