ryanmjacobs / C

Licence: mit
Compile and execute C "scripts" in one go!

Programming Languages

c
50402 projects - #5 most used programming language
shell
77523 projects
C++
36643 projects - #6 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to C

Ccache
ccache – a fast compiler cache
Stars: ✭ 1,128 (-41.25%)
Mutual labels:  compiler, clang, gcc
cdetect
🔬 Detect which compiler and compiler version a Linux executable (in the ELF format) was compiled with
Stars: ✭ 23 (-98.8%)
Mutual labels:  gcc, clang, tcc
rooki
A stupid simple script runner supporting c, c++, rust, haskell and virtually anything
Stars: ✭ 26 (-98.65%)
Mutual labels:  gcc, clang, tcc
Avalonstudio
Cross platform IDE and Shell
Stars: ✭ 1,132 (-41.04%)
Mutual labels:  clang, gcc
Iotz
compile things easy 🚀
Stars: ✭ 39 (-97.97%)
Mutual labels:  cli, compiler
C2goasm
C to Go Assembly
Stars: ✭ 1,072 (-44.17%)
Mutual labels:  clang, gcc
Croaring
Roaring bitmaps in C (and C++)
Stars: ✭ 735 (-61.72%)
Mutual labels:  clang, gcc
Cvise
Super-parallel Python port of the C-Reduce
Stars: ✭ 77 (-95.99%)
Mutual labels:  clang, gcc
Seriouscode
This header file enforces Clang warnings to bu turned-on for specific flags (almost everyone, at least each one I was able to find).
Stars: ✭ 68 (-96.46%)
Mutual labels:  compiler, clang
Ghdl
VHDL 2008/93/87 simulator
Stars: ✭ 1,285 (-33.07%)
Mutual labels:  compiler, gcc
Moderncppci
This is an example of doing a Modern C++ project with CI
Stars: ✭ 109 (-94.32%)
Mutual labels:  clang, gcc
Pfr
std::tuple like methods for user defined types without any macro or boilerplate code
Stars: ✭ 896 (-53.33%)
Mutual labels:  clang, gcc
Gccrs
GCC Front-End for Rust
Stars: ✭ 875 (-54.43%)
Mutual labels:  compiler, gcc
Tinycc
Unofficial mirror of mob development branch
Stars: ✭ 784 (-59.17%)
Mutual labels:  compiler, tcc
Cjstoesm
A tool that can transform CommonJS to ESM
Stars: ✭ 109 (-94.32%)
Mutual labels:  cli, compiler
Vector
➿ A supercharged std::vector implementation (minus Allocator)
Stars: ✭ 118 (-93.85%)
Mutual labels:  clang, gcc
Seeless
C IDE for iOS
Stars: ✭ 71 (-96.3%)
Mutual labels:  compiler, clang
Embedded Ide
IDE for C embedded development centered on bare-metal ARM systems
Stars: ✭ 127 (-93.39%)
Mutual labels:  clang, gcc
Gscript
framework to rapidly implement custom droppers for all three major operating systems
Stars: ✭ 547 (-71.51%)
Mutual labels:  cli, compiler
Sultan
Sultan: Command and Rule over your Shell
Stars: ✭ 625 (-67.45%)
Mutual labels:  cli, compiler

c

"There isn't much that's special about C. That's one of the reasons why it's fast."

I love C for its raw speed (although it does have its drawbacks). We should all 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.)

GIF Demo

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!

Hooked? Here's how to install it:

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 shebang will be different. For example it may be something more similar to #!/home/ryan/.bin/c.

Okay, how do I use it?

c will use whatever $CC is set to. You can change this with:

$ export CC=clang
$ export CC=tcc
$ # etc...

CLI

Multiple Files - CLI

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

Single File - CLI

With only one file, omit the quotes:

$ c hello.c
$ c main.c arg1 arg2

Shebang!

After adding a shebang, just set the file to executable and it's ready to run.

$ chmod +x file.c
$ ./file.c

Single File - Shebang

Add this to the top of your C file:

#!/usr/bin/c

Multiple Files - Shebang

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 --

Caching

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"

Contributing

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

Why?

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 of optimizations, just as GCC will perform its own and Clang will perform its own. The purpose of this script is to give a simple front-end to your favorite compiler.

Whether it's GCC, Clang, or something else entirely, you get to choose your 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 to write a small, fast, and portable C "script" is great. You can pass around a C "script" just like you would a BASH script.

zsh

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.

Packages

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)

Todo

Maybe later we can implement caching. Done!

License

MIT License.

Basically, you can do whatever you want provided that you include the LICENSE notice in any copy of the source. Also, I am not liable if the script breaks anything.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].