40% off your First Order with GoDaddy.com!

Feb 5, 2010

Run a C Program Directly

For this short tip you'll need tcc, the Tiny C Compiler, which comes with most distributions out there, including Debian and Ubuntu. tcc is a small ANSI C compiler which offers the ability to run the program after compiling it, unlike GCC, which (as far as I know) doesn't offer this option. To install tcc in Debian and Ubuntu:

In Debian, as root:
apt-get install tcc

In Ubuntu, use:
sudo apt-get install tcc

Now let's test this. First, create your C source file, e.g.:

Now, save this file as example.c or some other name and make it executable:
chmod 755 example.c # or chmod +x example.c

And the next step is just to run it!

"tcc" will compile the source and run it automatically.

No comments:

Post a Comment