We'll be programming the language C. In particular, we're using the C compiler clang, and the memory debugging tool valgrind. The preferred approach for doing this is to use Repl.it. You don't have to install anything locally on your own computer to do so. Most importantly, Repl.it allows you to pair program remotely simultaneously with others, and also share your code with us in real-time so that we can help you diagnose problems as you are working on them.

However, if you find that you wish to also install C / Valgrind locally on your computer, you might be able to. Using C is generally straightforward on most of the operating systems we're using. Valgrind, unfortunately, isn't practically usable on Macs for purposes of this course. I have instructions below for various operating systems. I want to again emphasize that Repl.it is the primary approach that we're using, and it will be much more difficult for us to support you remotely if you only install it locally. But I also understand that you may experience connection issues which may push you towards a local install.

Ubuntu Linux

The following instructions are for Ubuntu; if you are using an alternative Linux distribution, you'll need to figure out how to adapt accordingly. At a terminal prompt, enter the following:

sudo apt update && sudo apt upgrade
sudo apt install clang
sudo apt install valgrind

Windows

clang and Valgrind on Windows are supported via Windows Subsystem for Linux (WSL). If you haven't already installed WSL on your computer, see the instructions at the Microsoft WSL installation site. If you are doing this for the first time, select Ubuntu 20.04 LTS. Once it has been installed, start WSL by typing Ubuntu into the Windows search bar. This will give you a terminal window. To install C and Valgrind within, follow the instructions in the Ubuntu Linux section above.

Macs

Sadly, Macs are more cumbersome to get working properly than the other operating systems above, for a variety of reasons that I'm happy to discuss if people want to follow up with questions. clang is straightforward enough; Valgrind is a problem.

Installing clang, which is the C compiler

clang is included within Apple's Command Line Tools. Here are instructions on how to install. Once this process is done, open a terminal window, and type clang and hit enter. If you see something like:

$ clang
clang: error: no input files

... then clang is installed and working correctly.

Installing Valgrind, which is the memory diagnostic and debugging tool

Valgrind is a critical tool that we'll be using. It tells us if there are invisible memory errors in your code that you might not know about, which cause unpredictable behavior in your code. There are two problems with installing Valgrind on Macs.

  1. The Valgrind team is slow to adapt it to current versions of OS X, and it's never quite clear which versions of the operating system it will work for.

  2. It tells you that there are memory bugs in perfectly acceptable programs, for a complicated set of reasons. Professional developers who use Valgrind on Macs work hard over time to curate a suppressions file with a list of memory bugs that are spurious and thus ignorable for their own code. This supppresions file doesn't stay consistent for different versions of OS X. Maintaining such a suppressions file sadly isn't practical for this course.

So in short, don't do it. You might succeed at getting Valgrind to install via Homebrew; that depends on which version of OS X you have. But see #2 above: you won't get output from it that's believable. A number of students in past versions of this class have tried to make this work, and every time they walk away frustrated.

So how do you proceed? If you must work locally on a Mac, don't use Valgrind locally. Instead, I will have the GitHub auto tests set up to run Valgrind tests. You'll get reliable Valgrind testing done on GitHub's Linux testing servers. Unfortunately, the process is slow. You've already been watching the auto-testing process; you'll have to wait for the tests to complete before you can see where the errors are happening. But it's better than nothing.

But I want to say directly two things, which are frustratingly nearly inconsistent with each other:

So if you're on a Mac, use Repl.it for Valgrind testing if you at all can. If you can't, then use the results from GitHub autotesting.

And feel free to follow up on the Moodle Q&A if you want more info as to why Macs are such a problem for Valgrind.