SampleMidtermCS3214F10

SampleMidtermCS3214F10 - CS 3214 Sample Midterm Exam (Fall...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 3214 Sample Midterm Exam (Fall 2010) 1/15 Sample Midterm Exam (Fall 2010) Solutions are shown in this style. This exam was given in Fall 2010. 1. Compiling and Linking (25 pts) a) (2 pts) Prototypes. During project 3, your teammate added a function give_terminal_to() to the esh.c file like so: void give_terminal_to(pid_t pgrp, struct termios *pg_tty_state) { } When you compiled the project, you saw: $ make cc -Wall -Werror -Wmissing-prototypes -g -c -o esh.o esh.c cc1: warnings being treated as errors esh.c:196: warning: no previous prototype for ‘give_terminal_to’ make: *** [esh.o] Error 1 Your teammate then changed the code to be: void give_terminal_to(pid_t pgrp, struct termios *pg_tty_state); void give_terminal_to(pid_t pgrp, struct termios *pg_tty_state) { } Discuss the merits of this idea! Address whether the code now compiles or not, and whether your teammate suggested the correct approach! If not, describe the approach that should be used! The code compiles now, but the suggested fix is utterly bogus. Either the function should be defined static (if it is used only in esh.c), or else the prototype belongs in a header file such as esh.h b) Static Linking. Consider a static library built from multiple .c and multiple .h files with the arrangement shown below:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 3214 Sample Midterm Exam (Fall 2010) 2/15 i. (3 pts) Rows 1 and 2, 2 and 3, and 3 and 4 are connected by arrows that denote the relationship of these files during the build process. For each connection, name the tool that connects the files in each pairs of rows! You may use Unix shorthand names. a. Rows 1 to 2 C preprocessor (cpp or built into cc1, or gcc -E) b. Rows 2 to 3 The C compiler (cc1 or gcc) c. Rows 3 to 4 The archiver (ar) ii. (18 pts) Consider the following C declarations and definitions. For each declaration or definition, list all possible locations where a programmer may legally place them so that any program using libfilesupport.a will link and function correctly! Use the letters shown in the figure, i.e., A for file.h, B for dir.h, and so on! If a declaration needs to appear, or may appear in multiple files, say “A and B” or “A or B” as appropriate. In addition, list those files where an experienced programmer following best practices would place those declarations or definitions! Fill your answers into the table on the next page!
Background image of page 2
CS 3214 Sample Midterm Exam (Fall 2010) 3/15 Declaration/Definition Legal Placements Best Practice struct file; A – F Usually A, but could be repeated in B and C. struct file { // an open file struct list_elem elem; // link elem for open file list off_t pos; // current read/write offset }; A – F A (or D if struct is private to file.c) struct file *file_open (const char *name); A – F A (prefix matches file name) static struct file * get_file_helper (int fd); A – F D or E or F, as needed static off_t file_get_pos (struct file *f) { return f->pos; } A – F A static struct list open_file_list; D or E or F Likely D
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

SampleMidtermCS3214F10 - CS 3214 Sample Midterm Exam (Fall...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online