6.s096 Lecture 1

Lecture 1

  1. Introduction
  2. The Compilation Pipeline
    1. Preprocessing
    2. Compilation
    3. Linking
  3. Summary

# Introduction

Our TAs

No wait list: everyone's in! Also: grades

Why use C or C++?

# The Compilation Pipeline

How to compile a single file

How to compile multiple files

Compilation with Java

Compilation with Python

Compilation with C

# Preprocessing

The 3 commands we'll focus on today

#include

#define

Create your own dialect of Python!

#define with an argument

#ifdef

How to reveal the answer?

One way

Another way

#ifndef is the opposite of #ifdef

These are simple operations

#include

#include: just a string replacement

#define

#ifdef

# Compilation

Type-Checking

Returns string or int!

Type-checker sees only types

Type-checker's point of view

These don't match

Return type depends on arguments

Return type is declared

Cast a to float

All theoretical casts (left-to-right)

All allowed casts

No floating point ↔ memory address casts

Implicit casts

Numbers

Memory addresses of integers

Linear processing

Declaration and Definition

Could we put the definition in another file?

And perhaps the declaration too?

# Linking

If we remove the definition of answer

… error

Compile error

Link error

But we can put answer's definition in another file

The compile error remains

Fix it with a declaration (in a header file)

Best practice: include header here too

# Summary