<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TCC | 酷 壳 - CoolShell</title>
	<atom:link href="https://coolshell.cn/tag/tcc/feed" rel="self" type="application/rss+xml" />
	<link>https://coolshell.cn</link>
	<description>享受编程和技术所带来的快乐 - Coding Your Ambition</description>
	<lastBuildDate>Sun, 10 May 2009 07:24:15 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2</generator>
	<item>
		<title>用TCC可以干些什么？</title>
		<link>https://coolshell.cn/articles/786.html</link>
					<comments>https://coolshell.cn/articles/786.html#comments</comments>
		
		<dc:creator><![CDATA[陈皓]]></dc:creator>
		<pubDate>Sun, 10 May 2009 07:22:15 +0000</pubDate>
				<category><![CDATA[C/C++语言]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[编程工具]]></category>
		<category><![CDATA[编程语言]]></category>
		<category><![CDATA[Cinpy]]></category>
		<category><![CDATA[TCC]]></category>
		<guid isPermaLink="false">http://coolshell.cn/?p=786</guid>

					<description><![CDATA[<p>Tiny C Compiler 是一个微型的 C 语言编译器，支持 Windows 和 Linux 平台。其项目主页是： http://bellard.org/...</p>
<p class="read-more"><a class="btn btn-default" href="https://coolshell.cn/articles/786.html"> Read More<span class="screen-reader-text">  Read More</span></a></p>
The post <a href="https://coolshell.cn/articles/786.html">用TCC可以干些什么？</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></description>
										<content:encoded><![CDATA[<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415450859608158"
     crossorigin="anonymous"></script>Tiny C Compiler 是一个微型的 C 语言编译器，支持 Windows 和 Linux 平台。其项目主页是： <a href="http://bellard.org/tcc/" target="_blank">http://bellard.org/tcc/</a> 。你可以使用这个不到100K的编译器编译你的C文件，其支持C的预处理，编译，机器码汇编和链接。编译速度也超过了gcc，而且它支持ISO C99标准，并且，tcc还包括了一些内存和数组边界的检查。其还可以编译Linux的内核。</p>
<p>不过，TCC 最有趣的特性是可以用 UNIX 系统上常见的 #!/usr/bin/tcc 的方式来执行 ANSI C 语言写就的源程序，省略掉了在命令行上进行编译和链接的步骤，而可以直接运行 C 语言写就的源程序。这样就能做到像任何一种其它的脚本语言比如 Perl 或者是 Python 一样，显著的加快开发步调。可以像编写 Shell 脚本一样的使用 C 语言，随便想一想都觉得是一件奇妙的事情。但是 TCC 还有一些其它的特性呢！</p>
<p><span id="more-786"></span></p>
<p>在TCC这个超小型的C语言编译器下，我们还可以干得更多，比如这个开源项目：C in Python，项目主页是：<a href="http://www.cs.tut.fi/~ask/cinpy/">http://www.cs.tut.fi/~ask/cinpy/</a>，这个项目主要是让你可以在Python中直接使用C的源码。呵呵。</p>
<p>Cinpy 是一个Python的库，它可以让你在Python的模块中实现C的函数。在前些天，酷壳向大家介绍过《<a class="title" rel="bookmark" href="https://coolshell.cn/articles/671.html"><span style="color: #4c4c4c;">Python调用C语言函数</span></a>》——这主要是通过调用动态链接库的方式调用C的函数。而Cinpy则是直接在Python中写C语言。</p>
<p>我们来看一个示例：（部分代码）</p>
<pre data-enlighter-language="python" class="EnlighterJSRAW">
import ctypes
import cinpy

# Fibonacci in Python
def fibpy(x):
    if x&lt;=1: return 1
    return fibpy(x-1)+fibpy(x-2)

# Fibonacci in C
fibc=cinpy.defc(&quot;fib&quot;,
                ctypes.CFUNCTYPE(ctypes.c_long,ctypes.c_int),
                &quot;&quot;&quot;
                long fib(int x) {
                    if (x&lt;=1) return 1;
                    return fib(x-1)+fib(x-2);
                }
                &quot;&quot;&quot;)

# ...and then just use them...
# (there _is_ a difference in the performance)
print fibpy(30)
print fibc(30)
</pre>
<p>源代码这里下载：<a href="https://coolshell.cn/wp-admin/cinpy-0.10.tar.gz">cinpy-0.10.tar.gz</a><!--



<p align="center"><a href= target=_blank><img decoding="async" src=""></a></p>





<p align="center"><img decoding="async" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.weixin.jpg"> <img decoding="async" loading="lazy" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.mini_.jpg" width="300" height="300"> <br />关注CoolShell微信公众账号和微信小程序</p>

 

--></p>
<div style="margin-top: 15px; font-size: 16px;color: #cc0000;">
<p align="center"><strong>（转载本站文章请注明作者和出处 <a href="https://coolshell.cn/">酷 壳 &#8211; CoolShell</a> ，请勿用于任何商业用途）</strong></p>
</div>

<div class="wp_rp_wrap  wp_rp_vertical_m" id="wp_rp_first"><div class="wp_rp_content"><h3 class="related_post_title">相关文章</h3><ul class="related_post wp_rp"><li ><a href="https://coolshell.cn/articles/18360.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2018/05/300x262-150x150.jpg" alt="程序员练级攻略（2018)  与我的专栏" width="150" height="150" /></a><a href="https://coolshell.cn/articles/18360.html" class="wp_rp_title">程序员练级攻略（2018)  与我的专栏</a></li><li ><a href="https://coolshell.cn/articles/11265.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2014/03/snake-hat-new-year-schedule-800x960-150x150.jpg" alt="Python修饰器的函数式编程" width="150" height="150" /></a><a href="https://coolshell.cn/articles/11265.html" class="wp_rp_title">Python修饰器的函数式编程</a></li><li ><a href="https://coolshell.cn/articles/10822.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2013/12/yoda-lambda-150x150.png" alt="函数式编程" width="150" height="150" /></a><a href="https://coolshell.cn/articles/10822.html" class="wp_rp_title">函数式编程</a></li><li ><a href="https://coolshell.cn/articles/10169.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/5.jpg" alt="类型的本质和函数式实现" width="150" height="150" /></a><a href="https://coolshell.cn/articles/10169.html" class="wp_rp_title">类型的本质和函数式实现</a></li><li ><a href="https://coolshell.cn/articles/7886.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2012/07/muxnt-150x150.jpg" alt="代码执行的效率" width="150" height="150" /></a><a href="https://coolshell.cn/articles/7886.html" class="wp_rp_title">代码执行的效率</a></li><li ><a href="https://coolshell.cn/articles/4939.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/29.jpg" alt="Quora使用到的技术" width="150" height="150" /></a><a href="https://coolshell.cn/articles/4939.html" class="wp_rp_title">Quora使用到的技术</a></li></ul></div></div>The post <a href="https://coolshell.cn/articles/786.html">用TCC可以干些什么？</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></content:encoded>
					
					<wfw:commentRss>https://coolshell.cn/articles/786.html/feed</wfw:commentRss>
			<slash:comments>34</slash:comments>
		
		
			</item>
	</channel>
</rss>
