惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

Python | 酷 壳 - CoolShell

Python修饰器的函数式编程 | 酷 壳 - CoolShell 函数式编程 | 酷 壳 - CoolShell 二叉树迭代器算法 | 酷 壳 - CoolShell 一些有意思的算法代码 | 酷 壳 - CoolShell Python 和 PyGame 的一些示例 | 酷 壳 - CoolShell 在Javascript里写Python | 酷 壳 - CoolShell 五大基于JVM的脚本语言 | 酷 壳 - CoolShell Python处理encoding的小技巧 | 酷 壳 - CoolShell Python程序员的进化 | 酷 壳 - CoolShell 如何使用Python操作摄像头 | 酷 壳 - CoolShell 非常简单的Python HTTP服务 | 酷 壳 - CoolShell Erlang和Python互通 | 酷 壳 - CoolShell Python也Spring了 | 酷 壳 - CoolShell Python 自然语言处理 | 酷 壳 - CoolShell
用TCC可以干些什么? | 酷 壳 - CoolShell
陈皓 · 2009-05-10 · via Python | 酷 壳 - CoolShell

Tiny C Compiler 是一个微型的 C 语言编译器,支持 Windows 和 Linux 平台。其项目主页是: http://bellard.org/tcc/ 。你可以使用这个不到100K的编译器编译你的C文件,其支持C的预处理,编译,机器码汇编和链接。编译速度也超过了gcc,而且它支持ISO C99标准,并且,tcc还包括了一些内存和数组边界的检查。其还可以编译Linux的内核。

不过,TCC 最有趣的特性是可以用 UNIX 系统上常见的 #!/usr/bin/tcc 的方式来执行 ANSI C 语言写就的源程序,省略掉了在命令行上进行编译和链接的步骤,而可以直接运行 C 语言写就的源程序。这样就能做到像任何一种其它的脚本语言比如 Perl 或者是 Python 一样,显著的加快开发步调。可以像编写 Shell 脚本一样的使用 C 语言,随便想一想都觉得是一件奇妙的事情。但是 TCC 还有一些其它的特性呢!

在TCC这个超小型的C语言编译器下,我们还可以干得更多,比如这个开源项目:C in Python,项目主页是:http://www.cs.tut.fi/~ask/cinpy/,这个项目主要是让你可以在Python中直接使用C的源码。呵呵。

Cinpy 是一个Python的库,它可以让你在Python的模块中实现C的函数。在前些天,酷壳向大家介绍过《Python调用C语言函数》——这主要是通过调用动态链接库的方式调用C的函数。而Cinpy则是直接在Python中写C语言。

我们来看一个示例:(部分代码)

import ctypes
import cinpy

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

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

# ...and then just use them...
# (there _is_ a difference in the performance)
print fibpy(30)
print fibc(30)

源代码这里下载:cinpy-0.10.tar.gz

Loading...