UMBC CMSC 313, Computer Organization & Assembly Language, Spring 2013
[Up]
[Previous Lecture]
[Next Lecture]
Tuesday, April 9, 2013
Assigned: Proj7
Due: Proj6
Polymorphism in C
Assigned Reading in Null & Lobur:
Assigned Reading in Duntemann:
Slides (in PDF): none
Topics:
- Example of a C program passing a function pointer to an
assembly language program (for Project 7):
- Here's the flip side, an example of assembly language program passing a function pointer
to a C program:
- Using void * pointers and function pointers to achieve genericity.
(Programs posted below.)
Programs Shown:
These are all different implementations of a simple singly linked list
ADT.
- Version 1: plain vanilla linked list.
Each node is has an int data field.
Files:
README.txt
ll.c
ll.h
main01.c
- Version 2: uses #define constants DATA_TYPE
and DATA_TYPE_FORMAT for linked list of int.
Files:
README.txt
ll.c
ll.h
main02.c
- Version 3: this time define constants DATA_TYPE
and DATA_TYPE_FORMAT for linked list of double.
Files:
README.txt
ll.c
ll.h
main03.c
- Version 4: uses void * pointers that allow linked list
functions to point to different types of nodes. This works as long
as the next field is the first field in all the nodes.
Note that ll.c does not have to be recompiled to use it with
another node type.
Files:
README.txt
ll.c
ll.h
main04.c
main05.c
main06.c
main07.c
void_ptr.c
- Version 5: This version allows us to have both int
and double nodes in one linked list. Each node now stores a
pointer to a function that knows how to print that node.
Files:
README.txt
ll.c
ll.h
main08.c
main09.c
main10.c
main11.c
- Version 6: Previous version allowed only constant strings in
string nodes because of deallocation issues. In this version, each node
also has a delete function attached. Instead of storing another function
pointer in each node, we store a pointer to an array of function
pointers. Thus we have only one table for each type. Increasing the
number of functions in the table would not increase the size of each
node.
Files:
README.txt
ll.c
ll.h
main12.c
main13.c
main14.c
main15.c
main16.c
- Version 7: Clean up the code and make header files for each
type of linked list. The implemenations can be compiled separately and
placed in a library using the ar command.
We also make a linked list node that points to a linked list.
(See ll_list.c and
ll_list.h.)
This allows you to have linked lists of linked lists. Notice that
print_ll_node() and del_ll_node() can be implemented
quite simply using the linked list functions in ll.h.
Files:
README.txt
ll.c
ll.h
ll_double.c
ll_double.h
ll_int.c
ll_int.h
ll_list.c
ll_list.h
ll_string.c
ll_string.h
main17.c
main18.c
main19.c
main20.c
main21.c
Last Modified:
22 Jul 2024 11:28:16 EDT
by
Richard Chang
to Spring 2013 CMSC 313 Homepage