Homework 2

Computer Architecture I ShanghaiTech University
HW1 (in Autolab)    HW2 HW3

Task 1: 2D Doubly Linked Lists in C


You already learned how to implement a Doubly Linked List in the prerequisite courses such as Data Structures. Now, let's implement a 2D Doubly Linked List in C. You can find the detailed information and requirements in the header file doubll2d.h and the section Other Requirements. Implement the required functions by yourself in a file called "doubll2d.c".

Compilation of the source code requires no errors or warnings and conformity to the C89 standard. The Makefile syntax is given below.

CFLAGS=-Wpedantic -Wall -Wextra -Werror -std=c89

doubll2d.o: doubll2d.c doubll2d.h
  ${CC} ${CFLAGS} doubll2d.c -o doubll2d.o

Besides the functions that we pre-declared in doubll2d.h, you will need a main function to compile the code. You can come up with your own test cases in the main function to see whether your implementation is correct. However, when you submit the code, please only submit the implementation for the pre-declared functions. That is, your submission should NOT include any main function.

Your submission should only include the source code for the 2D Doubly Linked List, doubll2d.c. Any other file found will directly result in a grade of 0. We will also NOT be using your copy of the header file or Makefile.

We will test your program using the functions declared in the header file provided as well as some other functions defined by us. The output of the individual test cases will NOT be given in auto-grader and any attempt at retrieving the test cases or the program outputs will be seen as plagiarism.

Consider Learning Before You Start

Other Requirements

You are required to implement a 2D doubly linked list with following rules:


Refer to the submission section at the end.

Task 2: Libraries

For all tasks assume that doubll2d.h will be provided in the working directory and your doubll2d.c will be copied to the current working directory.

Task 2.1: Static Library


Write a shell script named staticlib.sh that when invoked, produces a static library named liblist.a from the source files doubll2d.c and doubll2d.h.

Then create a static-linked executable staticlist from liblist.a and test.c. Do not execute the program in the shell script.

Hint: use the command ar to create the static library. Then use the command ld to create the executable file.

Task 2.2 Dynamic-link Library


Write a shell script named dynamiclib.sh that when invoked, produces a dynamic-linked library named liblist.so from doubll2d.c.

Then generate an executable named dynamiclist using liblist.so as well as test.c. Do not execute the program in the shell script.


You should submit a compressed file named as hw2.tar to autolab.

The directory tree of your submission should look like the following :

├── doubll2d.c
├── dynamiclib.sh
└── staticlib.sh

Note: Autolab grading results:

Note (again): your submission should NOT contain any main() function

Test Environment

The test environment on autolab is Ubuntu 16.04 with gcc 5.x