Tiny C Compiler (TCC)

Source: Internet
Author: User

Catalog

1 . TCC Introduction2. TCC Installation Configuration 3. TCC programing

1. TCC Introduction

TCC Basic and GCC compatible

1. Complies with the ANSI C (c89/C90) specification 2. Complies with the new ISO C99 standard specification 3

Features of 0X1:TCC

The difference between TCC and other C language compilers is that

1The size of the small software is about 1MB and can be stored in 1.44MB disk slices for use2the program developed with TCC can run on x86 ( -/32-bit) with x86- -(64-bit) environment, the operation is relatively fast than that of GCC. The program can also contain assembly language (inline assembler) in which to run and compile3Unlimited other C-language dynamic libraries are subject to the ISO C99 specification and can be given to TCC for use and compilation4The . Security TCC contains an optional memory (memory) and BoundsChecker (program detector), the instrumented code can be arbitrarily mixed in the standard code, the other, TCC for command-line use, there is no integrated development environment, But can be used with other editing software (such as: UltraEdit ... , etc.)5. The TINYCC (TCC) is a small and fast C compiler. Unlike other C compilers, he can be self-reliant, and we don't need to extend the assembler or connector because TCC is ready6. TCC can also be used in C scripts, such as a C code that can run like a Perl or Python script. Compile quickly, like an executable (use the compiled language as an explanatory script)7. TCC also automatically generates memory bounds checks for all C pointer operations. TCC does this without a patch library8. Using LIBTCC, you can use TCC as the backend for dynamic code generation

0X2:TCC's application Scenario

Need to understand is that the TCC is a small embedded compiler, for the need to use the TCC program, need to merge the TCC source code into the main program to compile together, after the completion of the main program has the "code compile" this ability, can provide real-time code compilation, External third-party programs can be allowed to pass in C source code, even if compiled and executed directly in memory

1 2  22. 0 built-in lightweight c Compiler3. Expand C language 4 with LIBTCC . CINPY: A python library that allows you to implement C's function 5 in a python module . PHP TCC extension: Allow PHP to execute C code directly without compiling

0X3: Using assembly language

INYCC is integrated with the assembly, using TINYCC assembler syntax compatible with GNU assembler, but the use of the restrictions are still the following

1. Must be C or C + + directive has support 2. Because the pointer symbol is the same as C, there is no way to use thesymbol. " or "$"3. Supports 32-bit primary 4. Must be used for inline assembler inline assembly language (or inline assembler for continental terminology)

The associated assembly language syntax is supported as shown below

 .align N[,value]. Skip N[,value]. Space N[,value].  byte   value1[,...]. Word value1[,...].  short   value1[,...].  int   value1[,...].  long   value1[,...]. Quad immediate_value1[,...]. globl symbol.  global   symbol. section, text, data, BSS, fill repeat[,size[,value]]. org N. Previous. string  string  [,...]. Asciz  string  [,...]. ASCII  string  [,...]

Relevant Link:

http://Zh.wikipedia.org/wiki/tiny_c_compilerhttp://gashero.iteye.com/blog/ 1211797

2. TCC Installation Configuration

1<filename.c>2-run <filename.c>

Relevant Link:

http://bellard.org/tcc/http://Zh.wikipedia.org/wiki/tiny_c_compiler

3. TCC Programing

If you want to use the header file of a third-party library in the C source of TCC, you need to explicitly indicate the location of the library file on the compile command line

1.-B option set the TCC to find the path to the function library file 2. -I Option set the TCC to find the path of the C language header file

0x1: PHP TCC

apt-get install TCC installs pecl directly using the Yum install php-pear for installation pecl install TCC   pecl Install Channel ://pecl.php.net/tcc-0.1.2  

code.php

<? PHP         ' int main () {printf ("Hello World"); return 0;} ' ;         = tcc_new ();         = Tcc_compile_string ($TCC, $buf);  $ret = Tcc_run ($TCC);  ? >  

0X2:TCC in Python

Cinpy is a Python library that allows you to implement C functions in a Python module.

import ctypesimport cinpy # Fibonacciinchpythondef fibpy (x):ifx<=1:return 1    returnFibpy (x1) +fibpy (x2) # FibonacciinchCFIBC=CINPY.DEFC ("fib", cTYPES. Cfunctype (ctypes.c_long,ctypes.c_int),"""                LongFibintx) {if(x<=1)return 1; returnFIB (X-1) +fib (x2); }                """)# ... and then just use them...# (there _is_ a differenceinchThe performance) print fibpy ( -) Print FIBC ( -)

0x3: Using TCC from Script

CC can be called from a script, like a shell script. You only need to #! /usr/local/bin/tcc-run add to the beginning of your C source

#! /USR/LOCAL/BIN/TCC-<stdio.h>int  main () {    printf ("Hello world!\n ");     return 0 ;}

0x4: Using TCC from the command line

TCC can use the "-" option to read the C source code from the standard input to replace the input file, for example

' Main () {puts ("Hello");} ' | Tcc-run-

0x5: Using TCC in the Shell pipeline

There are two aspects to the cooperation between TCC and Shell pipelines

1. How the TCC compiler itself uses pipelines in GNUA common way to handle pipeline input on a/linux system is for the command-line program to handle a special minus sign (-) as a command-line argument. A command-line program that would need to read input data from a file, after receiving the minus sign as a command-line argument, reads the data from standard input (stdin) instead. This can be combined with the Shell's plumbing mechanism. But in the current TCC0.9. +The minus sign cannot be processed in the version as a command-line argument. But we can have an alternative to using the/dev/on the Gnu/linux system.stdin device file cat hello.c| tcc-run/dev/stdin///Dev/stdin is actually a symbolic link to/dev/fd/0, and the latter is a symbolic link to/dev/pts/0. If you don't have/dev/stdin on your gnu/linux system, you can also use/proc/self/fd/0 instead2. The C language script written by TCC How to use the pipe as long as the proper use of standard input (stdin) and standard output (stdout) in your C-language script can include<stdio.h>intMainintargcChar**argv) {    intC;  while((c = fgetc (stdin))! =EOF)        {FPUTC (c, stdout);    FPUTC (c, stdout); }    return 0;}

Relevant Link:

http://blog.csdn.net/shania_wang/article/details/5966492http://  blog.csdn.net/rainday0310/article/details/7618098http://coolshell.cn/articles/786.html https://www.ibm.com/developerworks/cn/linux/l-tinyc/part1/

Copyright (c) Littlehann All rights reserved

Tiny C Compiler (TCC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.