Assigned | Friday, January 6, 2017 |
---|---|
Due Date | Friday, January 13, 2017 at 11:59pm (23:59) |
Files | See "Acquiring the code" below. (Direct link here: arrays.c) |
Submissions | Submit your completed arrays.c using the course's Assignment Drop Box. |
The purpose of this assignment is to gain some very basic experience with C programming, including such topics as arrays, stack allocation, heap allocation, function calls, and memory safety (or the lack thereof). It is a credit/no credit exercise, and should take a short time to finish. Instructions on what to do are in the comments of the code you will download below.
To do the programming assignments in this course, you will either need [1] a virtual machine that you can run on your own laptop or desktop (if it supports 64-bit x86) or [2] access to the instructional cluster (named "klaatu").
All of you should be able to use a virtual machine. To install a virtual machine player on your own computer, follow the CSE Home VM instructions. If you have problems, you are probably not alone, so check out the course Discussion Board for any relevant discussions (or start a discussion yourself). You need to download the rather large VM file itself (it is ~ 3GB, so do this when you have good high bandwidth connectivity). This is a full linux environment with all the software we'll need this quarter pre-installed.
You can download arrays.c here from a browser.
Use wget
to download it from the command line.
In a terminal, run:
wget http://courses.cs.washington.edu/courses/cse410/17wi/labs/lab0/arrays.c
This should download arrays.c
, storing it in your current working directory.
A lecture on some basic Unix commands is available
here if you need help with this step.
If you are SSH'ed into klaatu, then you can copy the file directly from the class directory:
cp /courses/cse410/lab0/arrays.c .
Do note that the final period comes a space after "arrays.c" and is used to indicate that the destination is the current directory.
Now that you have acquired the source file, open arrays.c
in your favorite text editor.
This file contains a number of TODOs, which you are expected to complete.
Most have a proceeding line that says "Answer:",
which is where you should leave an answer to the question(s) posed in the TODO.
One TODO requires you to write some code,
which you should place immediately after the comment block that describes
what to do.
The source file arrays.c
won't do you any good by itself;
you need a compiler (specifically the GNU C compiler) to compile it to an
executable format. The GNU C compiler is available on the
CSE home VM, klaatu,
and most popular variants of Linux, such as Ubuntu and Fedora.
You are free to use whichever machine you like, although we will only provide
support for the CSE home VM and klaatu.
Using any one of these machines, open a terminal and execute
gcc -v
. On my machine, here is what I see:
$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-4/root/usr/libexec/gcc/x86_64-redhat-linux/5.2.1/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortr an,lto --prefix=/opt/rh/devtoolset-4/root/usr --mandir=/opt/rh/devtoolset-4/roo t/usr/share/man --infodir=/opt/rh/devtoolset-4/root/usr/share/info --with-bugur l=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix -- enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_ate xit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-b uild-id --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array -- disable-libgcj --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddi r/build/BUILD/gcc-5.2.1-20150902/obj-x86_64-redhat-linux/isl-install --enable-l ibmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 -- build=x86_64-redhat-linux Thread model: posix gcc version 5.2.1 20150902 (Red Hat 5.2.1-2) (GCC)
The output tells me a bunch of the configuration options for the
my installation of GCC as well as the version number, which is 5.2.1.
Assuming that you have saved the arrays.c
file somewhere on
your machine, navigate to that directory, and then use GCC to compile
it with the following command:
gcc -g -Wall -std=gnu99 -o arrays arrays.c
It's not that important right now for you to know what all of these
options do, but -g
tells the compiler to include debugging
symbols, -Wall
says to print warnings for all types of
potential problems, -std=gnu99
says to use the C99 standard
(now only 18 years old!), -o arrays
instructs the compiler
to output the executable code to a file called arrays, and
arrays.c
is the source file being compiled.
Having executed that command, you should be able to see a file named arrays in the same directory:
$ ls arrays arrays.c
The arrays file is an executable file, which you can run using
./arrays
. On my machine, here is what I see:
$ ./arrays Filling an array at address 0x7fff6b4e3e60 with 10 values Done! Filling an array at address 0x7fff6b4e3eac with 1 values Done! Filling an array at address 0x7fff6b4e3e90 with 4 values Done! Filling an array at address 0x11ca010 with 5 values Done!
If you look through the source code of the arrays.c file, you should be able to match up each line that is printed with the output that you see in the console.
With that, you should have everything you need to complete the
assignment. Note that every time you want to test a modification to
the source file, you will need to use the
gcc -g -Wall -std=gnu99 -o arrays arrays.c
command to
produce an updated arrays executable file.
When you have finished the exercise, please take the time to ensure that your code both compiles without warnings (the GCC command will output lines that say "warning:" if you have warnings) and is readable. In particular, please try to make the format of your code match that of what was given to you.
Once you have completed the exercise, submit your arrays.c
source file using the Assignment Drop Box.