CS 3330: Lab 0: Using C

This page does not represent the most current semester of this course; it is present merely as an archive.

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

We do not have the staffpower 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 schedule enough time with access to those machines in order 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.

C compilers

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.

On Windows the MinGW project has a version of gcc that will probably work for most (though not all) labs, though you will need to install it yourself. Microsoft's compiler toolchain can compile C using cl.exe /Tc filename.c, but we have never tested how well it works.

On OS X, Xcode ships with a version of llvm-gcc (they call it just gcc). On newer versions of the OS it is located inconveniently (/Applications/Xcode.app/Contents/Developer/usr/bin/gcc in 10.7 Lion) but can be placed where you can more easily access it from the Terminal via XCode's Preferences → Downloads → Command Line Tools → Install.

If you use another OS (FreeBSD, Haiku, Irix, etc) you probably know how run a C compiler already.

Linux Lite

We assume you'll use Linux for the labs in this course.

Upon logging into Linux, you'll want access to

  1. A terminal window
  2. An editor of some kind
  3. A web browser

I suggest getting the terminal first by pressing Alt-F2 and typing gnome-terminal, konsole, or xterm (they may not all work, but at least one should). You can also get to these from

You can then get an editor by typing into the terminal one of geany &, gedit &, kate &, nano, pico, emacs, or vim (or others, if you know others); and you can get a browser with firefox & or chromium-browser &.

Other important commands you can use in the terminal:

Online Compilers

In a pinch, there are lots of online compilers out there. You might try (in alphabetical order)

If you know of other online c compilers or have comments about these, tell your instructor so we can update this list.

Virtualbox

One of the most reliable ways to get a compliant C compiler if you don't run some kind of POSIX-compliant system is to install Linux via virtualbox.

You might already have a Linux virtual box from taking 2150. If you don't, get virtualbox and some Linux distro (Don't know which one? The labs use Kubuntu, but I hear nicer things about LMDE and xubuntu.). There are lots of tutorials on installing Linux on virtualbox online.

You may also use the virtualbox image Aaron Bloomfield created for CS 2150; see his tutorials on VirtualBox, Unix, and how he made the image if you wish. You'll find his image on collab's resources page, along with a smaller, less feature-rich image I made. Windows' built-in zip support might hang on such large files; if so, download 7zip to open them.

Testing your compiler

If you think you have a compiler properly installed,

  1. create hello.c from Figure 1.1 on page 2 of the textbook
  2. compile it as described in §1.2, and
  3. run it as described in §1.4
Copyright © 2015 by Luther Tychonievich. All rights reserved.
Last updated 2015-04-07 14:54 -0400