What is Unix?

Unix: a set of standards and tools commonly used in software development.

  • Macs are built on top of Unix
  • Linux is built on top of Unix

Every Unix system works with the same tools and commands

What is the Command Line?

The command-line is a text-based interface to navigate a computer, instead of a Graphical User Interface (GUI).

The C Language

C was created around 1970 to make writing Unix and Unix tools easier.

C doesn’t have

  • More advanced features like operator overloading, default arguments, pass by reference, classes and objects, ADTs, etc.
  • Extensive libraries (no graphics, networking, etc.) – this means not much to learn C!
  • many compiler and runtime checks (this may cause security vulnerabilities!)

C is procedural: you write functions, rather than define new variable types with classes and call methods on objects. C is small, fast and efficient.

/*
* hello.c
* This program prints a welcome message
* to the user.
*/
#include <stdio.h> // for printf
int main(int argc, char *argv[]) {
    printf("Hello, world!\n");
    return 0;
}

Import statements: C libraries are written with angle brackets. Local libraries have quotes: #include “lib.h”

Main function – entry point for the program Should always return an integer (0 = success)

Main parameters – main takes two parameters, both relating to the command line arguments used to execute the program. argc is the number of arguments in argv

argv is an array of arguments (char * is C string)

Boolean Variables

To make Boolean variables, (e.g. bool b = ____), you must import stdbool.h:

#include <stdbool.h> // for bool
ccc

Readings

The Strange Birth and Long Life of Unix “A damn stupid thing to do”—the origins of C