CS374: Programming Language Principles - The Compilation and Linking Processes

Activity Goals

The goals of this activity are:
  1. To describe the compilation process
  2. To define an algorithm to resolve linker dependencies using a multi-pass approach
  3. To define possible outcomes of the compilation process, including assembly code, machine code, and intermediate bytecode
  4. To describe the role of external libraries in extending the functionality of a programming language and the mechanisms for integrating them

Supplemental Reading

Feel free to visit these resources for supplemental background reading material.

The Activity

Directions

Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.

Model 1: Linker Processes


Questions

  1. Assume that we compile with gcc file1.c file2.c. What does the compiler have to do with the variable x in file1.c, since it does not yet know here the variable is declared?
  2. With what is the variable x updated in file1.c once it can resolve it to int x in file2.c?
  3. What does the assignment in a() do to the variable in file2.c?
  4. What if there was a variable in file2.c called a?
  5. What would happen if the variable x in file1.c was also initialized to a value when it was first declared?
  6. Under what circumstances do you think a variable is bound to a global, versus a linker error?
  7. In the C language, what do you think the static keyword does? How can we use this to protect global variables inside externally linked library functions?

Submission

I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.