CS 3330: Lab 0 (C and D)

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’ll also run a tool written in D (though we won’t write D ourselves).

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.

1 Suggested Techniques

Not all paths to C are created equal, but there are a lot of paths. This is my general priority order

  1. Program on the lab machines. For how to do this from home, see how to use ssh and scp.

    Warning: Do not submit files by copy-paste from ssh terminals without looking at them first! Copy-paste can introduce line breaks, backslashes, and so on where they do not belong.

  2. Go native. Install a good Linux distro, or make do with C and D on other OSs

  3. Use an online IDE; Cloud9 and Koding are known to work for all parts of this course; codio, ideone, and ShiftEdit might as well.

    One bit of setup, though: once you log in and open a project, get a terminal and type

    sudo apt-get update
    sudo apt-get install xdg-utils libc6-dev-i386 gcc-multilib make
    wget http://downloads.dlang.org/releases/2.x/2.071.1/dmd_2.071.1-0_amd64.deb
    sudo dpkg -i dmd_2.071.1-0_amd64.deb
  4. Use virtualization, such as virtualbox. Note, you’ll need a 64-bit image of Linux and will probably need to do the same extra setup steps as listed for an online IDE. Virtualization generally messes up timing, so it won’t be good for the last part of the course, but it should hold you over until then. See some tips on virtualization for more.

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

To get ANSI C behavior, add -ansi and -pedantic-errors to the command line.

If you have no main method, add -c to the command line.

3 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 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 &. 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:

4 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 © 2016 by Luther Tychonievich and Charles Reiss. All rights reserved.
Last updated 2016-08-12 13:00:04