Skip to Content

Introduction to CS 271

This intro is now updated to be appropriate for Spring 2023.

Plan and Purpose for the Course

  • teach the foundational ideas in Object Oriented Programming (OOP)
  • introduce students to the C/C++ world
  • give students better grounding in tools (git, github, compilers, make, etc.)
  • introduce plain C concepts even as we focus on C++

Translation of Programs into Executable Form

Computers and high-level programming languages (HLPL):

  • computers execute very basic machine instructions
  • hard to program at the lowest level (in CS 273 we do this)
  • high-level languages were invented to make it easier
  • need something to translate the HLPL into machine instructions

Compiled and interpreted languages:

  • two basic translators are compilers and interpreters
  • an interpreter translates the program at run-time. generally slow
  • a compiler translates the program once, and saves the resulting executable as a file so that it can be run many times
  • Java uses both a compiler and an interpreter
  • C/C++ typically only use a compiler

Real and virtual machines:

  • you can think of the meaning of a HLPL as a virtual machine
  • the actions of the virtual machine need translated onto a real machine, if we ever want to run the program
  • Java compiles a Java program onto another virtual machine, known as the Java Virtual Machine, or JVM. The JVM is implemented as an interpreted machine.
  • the JVM is defined in terms of a byte-code. The byte-code is stored in a .class file
  • C/C++ compilers compile your program directly down to the instructions that execute on the real machine

Execution Model of C/C++ Programs

C/C++ (and Java and many other languages) use a stack-based execution model, where functions/procedures/methods are called and executed using a stack:

  • most HLPLs give you the ability to call procedures/functions/methods
  • as these are called, a stack of active procedures is created
  • the data on the stack for an active procedure is called an activation record, or sometimes a call frame
  • the last-called procedure must finish before any of the previous
  • this stack-based model of procedure calls is very important to understanding how programs run

History of C and C++:

  • C was initially created (early 70’s) because Brian Kernigan, Dennis Ritchie, and Ken Thompson didn’t have any language they liked to write a new operating system for a new computer they had, a PDP-11.
  • This new OS became Unix
  • Much later, C was extended and standardized as ANSI C (late 80’s / early 90’s)
  • Simultaneously, Bjarne Stroustrup decided to add object-oriented ideas to C, and he called it C++ (mid-to-late 80’s)
  • C++ grew into a big language
  • Microsoft introduced a variant called C-Sharp, or C# (~2000)
  • Apple has long used another variant called Objective C