Assignment 7, due July 7

Part of the homework for 22C:50, Summer 2004
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. The standard C library routine fputc( char c, FILE * f) puts one character out to the given file. This is implemented using the standard Unix output routine write( int fd, char * buf, int size ). In effect, fputc does blocking (defined in Chapter 9), and its complement, fgetc does deblocking. For further details about either of these, refer to the documentaton available from the Unix/Linux man command. Note, because there are multiple write commands in different sections of the manual, you will need to say man 2 write in order to get the relevant document (section 1 of the manual documents shell commands, section 2 documents the operating system interface, section 3 documents the C standard library).

    a) Propose a representation of objects of type FILE as used in the C standard library to represent output data streams, inasmuch as you can infer this from the manual information about the putc and write calls.

    b) Propose an implementation of the fputc function in terms of your representation proposed in part a. Ignore any strangeness involved with interactive files.

    c) Explain why it is useful to have a macro, putc as well as a callable function, fputc to perform the same operation.

  2. Suppose you are responsible for implementing a character sequential driver such as the one discussed in Figure 10.8. Assume you are intent on using an object oriented implementation. It could be in a language like Java or C++, or you could fake it in C, this does not matter.

    a) What are the methods applicable to the objects of class queue that are required by this driver?

    b) What variables or data structures must be encapsulated into each queue object (that is, used for the representaton of each queue object)? To answer this question, you will have to select an appropriate queue implementation.

    c) When would you input/output driver allocate (instantiate) new queue objects and what would be the lifetime of these objects?