📄 tcc-doc.texi
字号:
\input texinfo @c -*- texinfo -*-@c %**start of header@setfilename tcc-doc.info@settitle Tiny C Compiler Reference Documentation@c %**end of header@include config.texi@iftex@titlepage@afourpaper@sp 7@center @titlefont{Tiny C Compiler Reference Documentation}@sp 3@end titlepage@headings double@end iftex@c @ifhtml@contents@c @end ifhtml@ifnothtml@node Top, Introduction, (dir), (dir)@top Tiny C Compiler Reference DocumentationThis manual documents version @value{VERSION} of the Tiny C Compiler.@menu* Introduction:: Introduction to tcc.* Invoke:: Invocation of tcc (command line, options).* Bounds:: Automatic bounds-checking of C code.* Libtcc:: The libtcc library.@end menu@end ifnothtml@node Introduction@chapter IntroductionTinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other Ccompilers, it is meant to be self-relying: you do not need anexternal assembler or linker because TCC does that for you.TCC compiles so @emph{fast} that even for big projects @code{Makefile}s maynot be necessary. TCC not only supports ANSI C, but also most of the new ISO C99standard and many GNUC extensions including inline assembly.TCC can also be used to make @emph{C scripts}, i.e. pieces of C sourcethat you run as a Perl or Python script. Compilation is so fast thatyour script will be as fast as if it was an executable.TCC can also automatically generate memory and bound checks(@pxref{Bounds}) while allowing all C pointers operations. TCC can dothese checks even if non patched libraries are used.With @code{libtcc}, you can use TCC as a backend for dynamic codegeneration (@pxref{Libtcc}).TCC mainly supports the i386 target. There are alpha ports for the ARM(@code{arm-tcc}) and the TMS320C67xx targets (@code{c67-tcc}). Moreinformation about the ARM port is available at@url{http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html}.@node Invoke@chapter Command line invocation[This manual documents version @value{VERSION} of the Tiny C Compiler]@section Quick start@example@c man begin SYNOPSISusage: tcc [options] [@var{infile1} @var{infile2}@dots{}] [@option{-run} @var{infile} @var{args}@dots{}]@c man end@end example@noindent@c man begin DESCRIPTIONTCC options are a very much like gcc options. The main difference is that TCCcan also execute directly the resulting program and give it runtimearguments.Here are some examples to understand the logic:@table @code@item @samp{tcc -run a.c}Compile @file{a.c} and execute it directly@item @samp{tcc -run a.c arg1}Compile a.c and execute it directly. arg1 is given as first argument tothe @code{main()} of a.c.@item @samp{tcc a.c -run b.c arg1}Compile @file{a.c} and @file{b.c}, link them together and execute them. arg1 is givenas first argument to the @code{main()} of the resulting program. Becausemultiple C files are specified, @option{--} are necessary to clearly separate theprogram arguments from the TCC options.@item @samp{tcc -o myprog a.c b.c}Compile @file{a.c} and @file{b.c}, link them and generate the executable @file{myprog}.@item @samp{tcc -o myprog a.o b.o}link @file{a.o} and @file{b.o} together and generate the executable @file{myprog}.@item @samp{tcc -c a.c}Compile @file{a.c} and generate object file @file{a.o}.@item @samp{tcc -c asmfile.S}Preprocess with C preprocess and assemble @file{asmfile.S} and generateobject file @file{asmfile.o}.@item @samp{tcc -c asmfile.s}Assemble (but not preprocess) @file{asmfile.s} and generate object file@file{asmfile.o}.@item @samp{tcc -r -o ab.o a.c b.c}Compile @file{a.c} and @file{b.c}, link them together and generate the object file @file{ab.o}.@end tableScripting:TCC can be invoked from @emph{scripts}, just as shell scripts. You justneed to add @code{#!/usr/local/bin/tcc -run} at the start of your C source:@example#!/usr/local/bin/tcc -run#include <stdio.h>int main() @{ printf("Hello World\n"); return 0;@}@end example@c man end@section Option summaryGeneral Options:@c man begin OPTIONS@table @option@item -vDisplay current TCC version.@item -cGenerate an object file (@option{-o} option must also be given).@item -o outfilePut object file, executable, or dll into output file @file{outfile}.@item -BdirSet the path where the tcc internal libraries can be found (default is@file{PREFIX/lib/tcc}).@item -benchOutput compilation statistics.@item -run source [args...]Compile file @var{source} and run it with the command line arguments@var{args}. In order to be able to give more than one argument to ascript, several TCC options can be given @emph{after} the@option{-run} option, separated by spaces. Example:@exampletcc "-run -L/usr/X11R6/lib -lX11" ex4.c@end exampleIn a script, it gives the following header:@example#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11#include <stdlib.h>int main(int argc, char **argv)@{ ...@}@end example@end tablePreprocessor options:@table @option@item -IdirSpecify an additional include path. Include paths are searched in theorder they are specified.System include paths are always searched after. The default systeminclude paths are: @file{/usr/local/include}, @file{/usr/include}and @file{PREFIX/lib/tcc/include}. (@file{PREFIX} is usually@file{/usr} or @file{/usr/local}).@item -Dsym[=val]Define preprocessor symbol @samp{sym} toval. If val is not present, its value is @samp{1}. Function-like macros canalso be defined: @option{-DF(a)=a+1}@item -UsymUndefine preprocessor symbol @samp{sym}.@end tableCompilation flags:Note: each of the following warning options has a negative form beginning with@option{-fno-}.@table @option@item -funsigned-charLet the @code{char} type be unsigned.@item -fsigned-charLet the @code{char} type be signed.@item -fno-commonDo not generate common symbols for uninitialized data.@end tableWarning options:@table @option@item -wDisable all warnings.@end tableNote: each of the following warning options has a negative form beginning with@option{-Wno-}.@table @option@item -Wimplicit-function-declarationWarn about implicit function declaration.@item -WunsupportedWarn about unsupported GCC features that are ignored by TCC.@item -Wwrite-stringsMake string constants be of type @code{const char *} instead of @code{char*}.@item -WerrorAbort compilation if warnings are issued.@item -Wall Activate all warnings, except @option{-Werror}, @option{-Wunusupported} and@option{-Wwrite-strings}.@end tableLinker options:@table @option@item -LdirSpecify an additional static library path for the @option{-l} option. Thedefault library paths are @file{/usr/local/lib}, @file{/usr/lib} and @file{/lib}.@item -lxxxLink your program with dynamic library libxxx.so or static librarylibxxx.a. The library is searched in the paths specified by the@option{-L} option.@item -sharedGenerate a shared library instead of an executable (@option{-o} optionmust also be given).@item -staticGenerate a statically linked executable (default is a shared linkedexecutable) (@option{-o} option must also be given).@item -rdynamicExport global symbols to the dynamic linker. It is useful when a libraryopened with @code{dlopen()} needs to access executable symbols.@item -rGenerate an object file combining all input files (@option{-o} option mustalso be given).@item -Wl,-Ttext,addressSet the start of the .text section to @var{address}.@item -Wl,--oformat,fmtUse @var{fmt} as output format. The supported output formats are:@table @code@item elf32-i386ELF output format (default)@item binaryBinary image (only for executable output)@item coffCOFF output format (only for executable output for TMS320C67xx target)@end table@end tableDebugger options:@table @option@item -gGenerate run time debug information so that you get clear run timeerror messages: @code{ test.c:68: in function 'test5()': dereferencinginvalid pointer} instead of the laconic @code{Segmentationfault}.@item -bGenerate additional support code to checkmemory allocations and array/pointer bounds. @option{-g} is implied. Notethat the generated code is slower and bigger in this case.@item -bt NDisplay N callers in stack traces. This is useful with @option{-g} or@option{-b}.@end tableNote: GCC options @option{-Ox}, @option{-fx} and @option{-mx} areignored.@c man end@ignore@setfilename tcc@settitle Tiny C Compiler@c man begin SEEALSOgcc(1)@c man end@c man begin AUTHORFabrice Bellard@c man end@end ignore@chapter C language support@section ANSI CTCC implements all the ANSI C standard, including structure bit fieldsand floating point numbers (@code{long double}, @code{double}, and@code{float} fully supported).@section ISOC99 extensionsTCC implements many features of the new C standard: ISO C99. Currentlymissing items are: complex and imaginary numbers and variable lengtharrays.Currently implemented ISOC99 features:@itemize@item 64 bit @code{long long} types are fully supported.@item The boolean type @code{_Bool} is supported.@item @code{__func__} is a string variable containing the currentfunction name.@item Variadic macros: @code{__VA_ARGS__} can be used for function-like macros:@example #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__)@end example@noindent@code{dprintf} can then be used with a variable number of parameters.@item Declarations can appear anywhere in a block (as in C++).@item Array and struct/union elements can be initialized in any order by using designators:@example struct @{ int x, y; @} st[10] = @{ [0].x = 1, [0].y = 2 @}; int tab[10] = @{ 1, 2, [5] = 5, [9] = 9@};@end example @item Compound initializers are supported:@example int *p = (int [])@{ 1, 2, 3 @};@end exampleto initialize a pointer pointing to an initialized array. The sameworks for structures and strings.@item Hexadecimal floating point constants are supported:@example double d = 0x1234p10;@end example
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -