CS Behind the Curtain (CS195 2003S)

Functions

Warning! This lab may be even more sketchy than most.

Summary: In this laboratory, we consider various aspects of functions in C.

Contents:

Exercises

Exercise 0: Preparation

Make a new directory for this laboratory.

Exercise 1: Predeclarations

Determine through experimentation, answers to the following questions:

Exercise 2: External Declarations

Typically, we build collections of utility functions, in which the collection is separately declared and separately compiled. You may recall dealing with some sample libraries in an earlier lab.

a. Refresh your memory on how to build a separate library.

b. What happens if the extern declaration for a function doesn't match the actual function definition (e.g., if they return different types of take different kinds of parameters)?

c. What techniques would you suggest to help avoid problems of incorrect calls? (Not changes to the languages, but techniques your or your colleagues could use.)

Exercise 3: Recursion

a. Write a tail-recursive function and determine experimentally whether out compiler does tail-recursion elimination (also called tail-call eliminatino).

b. Turn on optimization and see if that makes a difference.

c. Read our manual to learn more about tail-calls.

Exercise 4: Register Variables

Most functions are much quicker if their parameters are passed in registers rather than on the stack.

a. How would you determine how our compiler normally passes parameters?

b. Reading the documentation, is there a way to tell it to pass parameters in registers rathe than on the stack?

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Fri May 2 14:19:47 2003.
The source to the document was last modified on Mon Feb 24 15:31:47 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS195/2003S/Labs/functions.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu