CS253: Software Development with C++

Fall 2022

Introduction

Show Lecture.Introduction as a slide show.

CS253 Introduction


Bjarne Stroustrup presents C++ to the Founding Fathers

Things you need to know

a picture of Jack Applin, looking strict
Do I look like your mother?
  • E.g. = “for example”.
  • I.e. = “in other words”.
  • Emit = “produce”. Fires emit smoke. Emit ≠ omit.
  • Oxford Comma: A, B, and C.
  • No Canvas messages/submission comments; email or Teams.
  • No email/Teams images; plain text.
  • ISO 8601: 2024‒05‒05 = May  5, 2024.
  • L toggles link underlining.
  • Learn to read documentation: if, getopt(), cp.
  • 11:59ᴘᴍ MT Saturday means just that.
  • Unpack/build error? No points.
    • It can be easily fixed?
    • It worked on your computer?
    • You worked really hard on it?
    • Needed for a scholarship?
    • Parents will be angry?
      • Still no points.

Origin

a picture of Bjarne Stroustrup
B-Strous

Dialects

Standards

auto 🐵=[](){ return "🍌"; };
cout << 🐵();
🍌

Authorities

The important part is not the answer, it’s the “according to”.

Who’s the best pop singer?

Beyoncé, according to … not the BeyHive, but the population

When is the holiday Washington’s Birthday?

the third Monday in February, according to … the U.S. Congress

Is Pluto a planet?

no, according to … the International Astronomical Union

How long is a meter?

1⁄299792458 light-second, according to … ISO

Standard C++

Standard

An HP co-worker, Donn Terry, used to say “Standard is better than better”. This meant that doing something in the standard way is superior to doing it in a non-standard way, even if the non-standard way yields better results. True enough, as far as it goes.

If all you know is Australian English, thick with local slang, you’ll have a difficult time being understood in Detroit. Knowing Standard English can be useful.

I want you to learn standard C++. That way, your programs will work everywhere, on any standard-conforming compiler. If you use compiler extensions, non-standard features, then your program will work on that particular compiler, but perhaps not on others. Not so good.

C++ is C

When C++ was being developed, C compatibility was very important. It still is. There are zillions of C programs out there, and the creator of C++ wanted it to be very easy to take a C program and turn it into a C++ program.

Therefore, C++ is just about a superset of C. This means that almost all C programs are C++ programs.

Valid C & C++

This is a valid C program, and a valid C++ program:

#include <stdio.h>
int main() {
    printf("Hello from C!\n");
    return 0;
}
Hello from C!

#include <stdio.h>
int main() {
    printf("Hello from C++!\n");
    return 0;
}
Hello from C++!

printf() is as much a part of C++ as int and while. 99.454% of C programs are valid C++.

C++, not C


It’s the Bad Code Badger !

This is a valid C program, but not a C++ program, because C++ claimed class as a keyword:

int main() {
    int class = 253;
    printf("C: %d\n", class);
    return 0;
}
C: 253

int main() {
    int class = 253;  // 🦡
    printf("C++: %d\n", class);
    return 0;
}
c.cc:2: error: expected primary-expression before ‘int’

This is a rare exception.

Better C++

Sure, it’s better C++ style to do the first program like this:

#include <iostream>
using namespace std;
int main() {
    cout << "Hello, world!\n";
    return 0;
}
Hello, world!

However, that doesn’t change the fact that the first program is C++.

A Final Note