"There isn't much that's special about C. That's one of the reasons why it'sfast."
I love C for its raw speed (although it does have its drawbacks). We shouldall write more C.
With this shell script, you can compile and execute C "scripts" in one go!
(Oh yeah, and it works for C++ too.)
Here's a simple example:
#include <stdio.h>
int main(void) {
printf("Hello World!\n");
return 0;
}
Run it by typing:
$ c hello.c
Hello World!
Or, call it from the shebang!
#!/usr/bin/c
#include <stdio.h>
int main(void) {
printf("Hello World!\n");
return 0;
}
$ chmod +x hello.c
$ ./hello.c
Hello World!
Use a package manager? Check here.
For the entire system:
$ wget https://raw.githubusercontent.com/ryanmjacobs/c/master/c
$ sudo install -m 755 c /usr/bin/c
# Or... for systems that prefer /usr/local/bin (e.g. macOS)
$ sudo install -m 755 c /usr/local/bin/c
For your local user only:
$ wget https://raw.githubusercontent.com/ryanmjacobs/c/master/c
$ sudo install -Dm 755 c ~/.bin/c
$ echo 'PATH=$PATH:$HOME/.bin' >> ~/.bashrc
Note: if you install it somewhere other than /usr/bin/c
, then your shebangwill be different. For example it may be something more similar to#!/home/ryan/.bin/c
.
c will use whatever $CC
is set to. You can change this with:
$ export CC=clang
$ export CC=tcc
$ # etc...
Anything you want passed to the compiler, put in quotes as the first argument.Whether they're flags (-Wall
, -O2
, etc.) or file names (file.c
,main.c
, etc.).
$ c "main.c other.c" arg1 arg2
$ c "main.c other.c -O3 -Wall -lncurses" arg1 arg2
With only one file, omit the quotes:
$ c hello.c
$ c main.c arg1 arg2
After adding a shebang, just set the file to executable and it's ready to run.
$ chmod +x file.c
$ ./file.c
Add this to the top of your C file:
#!/usr/bin/c
Just tack on any extra flags, options, or files you want passed to the compiler.Then be sure to add the terminating --
characters.
#!/usr/bin/c file1.c file2.c -lncurses -lm --
The default cache size is set to 5 MB. You can change this with:
$ export C_CACHE_SIZE=$((10*1024)) # 10 MB
The default cache path is set to $TMPDIR/c.cache
. You can change this with:
$ export C_CACHE_PATH="/tmp/the_cache"
Feel free to submit any ideas, questions, or problems by reporting an issue.Or, if you're feeling a bit brave, submit a pull request.
Just hack away and make sure that all the tests pass.
$ cd tests
$ ./test.sh
First of all, I want to clarify why this is not the same as tcc -run
.TCC is a compiler. We all know that. TCC will perform its own set ofoptimizations, just as GCC will perform its own and Clang will perform itsown. The purpose of this script is to give a simple front-end to your favoritecompiler.
Whether it's GCC, Clang, or something else entirely, you get to chooseyour compiler.
Second reason: it's simply satisfying to type c hello.c
and see it run instantly.
Third reason: I'm a fan of speed, and C definitely offers it. Being able towrite a small, fast, and portable C "script" is great. You can pass around aC "script" just like you would a BASH script.
If you're using zsh
, then you can take advantage of zsh
's suffix aliases:
$ alias -s c='c'
$ alias -s cc='c'
$ alias -s cpp='c'
Then you can run files with ./file.c
without chmod +x
.
Use a package manager? You've come to the right place.
AUR: https://aur.archlinux.org/packages/c/
bpkg: bpkg install ryanmjacobs/c
brew: brew install https://raw.githubusercontent.com/ryanmjacobs/c/master/c.rb
(shebang will be #!/usr/local/bin/c
)
Maybe later we can implement caching.
Done!
Basically, you can do whatever you want provided that you includethe LICENSE notice in any copy of the source. Also, I am not liableif the script breaks anything.
【Educoder作业】C&C++数组实训 数组是很好用的。作为一个最基本的数据结构,数组是构成高级结构的基础。简单点的比如列表的next和head指针,桶的下标,栈;复杂点的比如说线段树的节点,KD树的平面,我们都需要数组进行实现。 T1 销售波动统计 这个题目显然是容易的,注意不要从 i = = 0 i==0 i==0开始即可。 #include <stdio.h> #include <ios
<c:choose>就像在Java switch语句,它可以让你在一些替代方案之间选择。switch语句中有case语句,<c:choose>标签具有<c:when>标签。switch语句中有默认default子句来指定一个默认的行为,类似的方式<c:choose>已<c:otherwise>作为default语句。 属性: <c:choose>标签没有任何属性。 <c:when>标记有一个属性,
<c:choose> <c:when test="${dy:hasAllOperORV2(SESSION_USER_V2, 'PRP_Edit_Descript')}> <div class="boxTitle"> <b>工作清单</b>
用C实现AI的过程中,有几点需要考虑: 1. 编程中内存的存取 2. 算法的精神 3. 数据种类的使用 4. 算法最终的理想结果 5. 完成基本功能之后,思考如何optimization。 原则:simpler, better 结合这几点,考虑,将C体现的AI简单地表现出来。
Linux上使用的C编译器是GNU C编译器,其对标准的C(ansi c)进行了一定的扩展,这带来的影响是两方面的。一方面增强了其原来的没有的功能,另一方面却对要编写移植性要求较高的程序带来了一些问题。对于后一个问题,在编写程序时,建议是如果在ANSI C中也提供的同样的功能时,尽量使用ANSI C来实现,当然如果不考虑程序的移植性,比如说,我们就是要在一个产品上写一段代码,那就不需要考
scanf("%c",&c) 与 scanf(" %c",&c)的区别 scanf("%c",&c) 与 scanf(" %c",&c),后者只是在%前多了个空格,似乎没有什么区别,但使用起来区别是很大的。 scanf()作单字符输入时规定只接收一个字符,但它却把回车符也作为字符对待的。这个回车符是放在缓冲区的,但是空格却是直接忽略掉。 这就造成程序中第二次调用scanf("%c",&c)是从缓冲
在使用scanf读入一系列字符时,经常要处理上一次读入时遗留下来的回车符,因为在使用scanf读入字符串时,回车符也会被当成一个字符来读入,所以常常会导致我们读入发生错误。 一般处理的思路 : 使用getchar()吃掉一次回车 getchar(); 其实还可以使用: scanf(" %c, &c); 这样就可以不用使用getchar()了,是不是很方便~ scanf(" %c", &c)与s
C是C++的一个子集 C面向过程,C++具有面向对象的特性,java是面向对象语言。 C的函数句柄只用函数名区分,C++函数句柄用函数名+参数区分 所以c不支持重载 C里struct和C++里struct不用 关 于 重 载 和 覆 写 : {\red{关于\ 重载\ 和\ 覆写:}} 关于 重载 和 覆写: 有种说法是,重载是同名函数参数不同,覆写是子类重写父类函数。 还有说法是,重
面试题中C&C int c = 23; printf(“%d\n”, c&c); 可以看到C是一个int类型的的数据 //&,按位与 0101 1010 &----- 0000 //两者均为1则为1 所以C&C是 0001 0111 &0001 0111 ----------- 0001 0111 所以其实两个相同的数进行与运算,其结果都是本身。 我是一个学习C/C++的小白,
String abc="aaa"; char c=abc.charAt(i); c+=4; 以上如果把:c+=4; 改成:c=c+4; 就不正确。 ******************************************************************************************************************************
C/C++:参与运算的两数各对应的二进位相与 &:按位与 (只有对应的两个二进位均为1时,结果位才为1,否则为0) 例:x=3&3; x值:3 x=3&4;x值:0 x=3&1;x值:1 3 0011 4 0100 1 0001 &&:与运算(0代表false,其他数值代表true) 例:x=3&&3; x值:1 x=0&&4;x值:0 |:按位或(对应的两个二进位1,0为1,1,1为1) 例:x
今天在看the c proarmming language (second edition)..中文版..老外的书.怎么说呢...跟国内的书真的好大区别..在哪也说不清楚...总觉得老外的书看起来有劲````做了几个例题..也可以.做到一题http://community.csdn.net/Expert/topic/5099/5099612.xml?temp=.6459314 我刚接触C(自学)
一维数组 int a[10]; int *c; c=&a[0] //&a[0]是指向数组第一个元素的指针 array[i]=*(array+i) &array[i]=array+i=array[0]+i -------------------------------------- -------------------------------------- int array[10]; int
一、<C:If>标签:条件判断语句 <c:if>标签判断表达式的值,如果表达式的值为 true 则执行其主体内容。 标签有如下属性: 属性 描述 是否必要 默认值 test 条件 是 无 var 用于存储条件结果的变量 否 无 scope var属性的作用域 否 page test为if语句的判断条件。执行与java中的一致。 实例演示: <%@ page language="java" con
示例 package main import ( "net/http" "github.com/gin-gonic/gin" ) type Article struct { Title string // 变量名首字母需要大写,不然会返回一个空的结构体 Desc string `json:"desc"` // 这种格式可以使变量名输出为小写 Content string
const char* 常量指针,表示指向的内容为常量。指针可以指向其他变量。但是内容不能变。 char *const 是指针常量,表示地址是常量,不能改变,当时指针指向的内容可以改变。 C语言操作文件 fopen( _In_z_ char const* _FileName, _In_z_ char const* _Mode ); errno_
extern关键字的用法 一个c文件需要调用另一个c文件里的变量或者函数,而不能从.h文件中调用变量。 extern int a=5和int a=5意义是一样的,都是定义。而extern int a是声明。 对于函数而言,和引用变量是一样的,如果需要调用其他c文件中的函数,在文件中的函数声明前加extern即可,不加extern而直接声明函数也可以,因为声明全局函数默认前面带又extern。 如果
定位到源码的uCOS-II/Ports/ARM-Cortex-M3/Generic/IAR/os_cpu_c.c: os_cpu_c.c定义了9个钩子(Hook)函数和一个堆栈初始化函数。 所谓钩子函数,是那些插入到某些函数中以扩展这些功能的函数,一般钩子函数是为第三方软件开发人员提供的扩充软件功能的入口。为了系统使用者扩展系统功能,uCOS-II中提供很多的钩子函数,使用者可以不修改
在用spring mvc中,页面前端老用jstl, <c:choose>、<c:when>和<c:otherwise>在一起连用,可以实现Java语言中的if-else语句的功能。例如以下代码根据username请求参数的值来打印不同的结果: <c:choose> <c:when test="${empty param.username}"> Nnknown user.
一些辅助脚本,多数为外部 Makefile 调用。
scripts 启动 peer 节点的脚本。
Codeship Scripts A public collection of useful scripts for use on Codeship and similar tools. E.g. scripts to install specific versions of software not included by default on the build VMs. Deployment
The startup and shutdown scripts with their configuration files. SliTaz and startup SliTaz does not use a level of execution (runlevel), the system is initialized via a primary script and its main con
Content Scripts Contents Manifest Include和exclude语句 编程式注入 h3Name 执行环境 h3Name 与嵌入的页面通信 h3Name 安全性 h3Name 引用扩展里的文件 h3Name 例子 h3Name 视频(Youtube) h3Name Content Scripts Content scripts是在Web页面内运行的javascrip
Color-Scripts Color scripts created by various people that was scattered around the web now in one place. You will find screenshots in the directory named preview All the scripts have been baptized wi
Guidelines for Hacktoberfest 2021: About Hacktoberfest: Hacktoberfest is organised by DigitalOcean in partnership with Dev, Intel, DeepSource & Appwrite. It is a month-long celebration of open-source
blogfoster-scripts Single-command, zero-config tooling for Node.js projects blogfoster-scripts is a wrapper around some of our favorite JavaScript tools. It unifies developer experience across multipl