This lab is optional. Olsson 001 will not be staffed today, so you’ll need to do it on your own. If you run into problems, use Piazza to get help.
We will use C (not C++, C#, Objective-C, Ch, C0, C–, or any other C-named language) in much of this class. C is very close to machine language without the headaches associated with the assembly language. We’ll also run a tool written in Rust (though we won’t write Rust ourselves).
We do not have the staff power to support arbitrary student systems or arbitrary C compilers. If the suggestions below fail for any reason, our official answer is
you may program on the lab machines instead. It is on you to arrange access to those machines to complete your assignments. Excuses such as
my computer crashed or
I had trouble installing the compiler will not be accepted.
That said, we will sometimes provide suggestions for how a lab or homework could be done from your home machine. If those work for you, great. If they do not,
you may program on the lab machines instead. If you have your own tip, post it on piazza so everyone can benefit.
Not all paths to C are created equal, but there are a lot of paths. This is my general priority order
- Program remotely on the department Unix machines. For how to do this from home, see how to use remote desktop,
scp. These machines come with a version of
gccby default, but you can access a more recent C compiler by running
module load gcc(for
module load clang(for
clang). (See also this guide to modules on the department machines.)
Warning: Do not submit files by copy-paste from
sshterminals without looking at them first! Copy-paste can introduce line breaks, backslashes, and so on where they do not belong.
- Go native. Install a good Linux distro, or make do with C on other OSs
- Use virtualization, such as VirtualBox. Note, you’ll need a 64-bit image of Linux like the one 2150 has used recently. Virtualization occasionally messes up timing, so it might not be good for the last part of the course, but it should hold you over until then.
- Use an online IDE; Cloud9 and Koding are known to work for all parts of this course (but maybe a bit slow for the performance assignments); codio, ideone, and ShiftEdit might as well. One bit of setup, though: once you log in and open a project in one of these online IDEs, get a terminal and type
sudo apt-get update sudo apt-get install xdg-utils libc6-dev-i386 gcc-multilib make
C command line
C files can be compiled on any Linux system using
gcc -x c filename.c,
clang -x c filename.c, or
llvm-gcc -x c filename.c. Most systems will have only one of these three installed; it does not matter which one you use.
If you have no
main method or otherwise want to produce an object file instead of a final executable, add
-c to the command line.
Recent compilers on the lab machines
On the lab machines, the default
gcc is pretty old, but you can get access to more recent one by running
module load gcc. Similarly, a recent version of
clang is available with
module load clang.
We assume you’ll use Linux for the labs in this course.
Upon logging into Linux, you’ll want access to
- A terminal window
- An editor of some kind
- A web browser
I suggest getting the terminal first by pressing Alt-F2 and typing
xterm (they may not all work, but at least one should).
You can then get an editor by typing into the terminal one of
vim (or others, if you know others); and you can get a browser with
firefox & or
chromium-browser &. The
& means “Run this in the background and let me type other stuff in the terminal while it is running”.
Other important commands you can use in the terminal:
pwdtells you where you are currently in the file system
lstells you what files are in the current folder
mkdirmakes a new directory
cd ..go one spot higher in the directory tree (if you are in
cd ..will move you to
cd dirnameto enter directory dirname (if you are in
cd wheewill move you to
- The Tab key will autocomplete what you are typing; pressing it twice will list all possible autocompletion results. For example, instead of typing
/home/mst3k/funbox/whee/I can probably type
whTab. This not only saves typing, but it also reduces the chances of typos.
You might also be interested in this Unix tutorial (from our local research computing center).
Testing your compiler
If you think you have a compiler properly installed,
hello.cfrom Figure 1.1 on page 2 of the textbook
- compile it as described in C command Line Section §1.2, and
- run it
You don’t have to submit anything for the lab.