Show Lecture.Introduction as a slide show.
CS253 Introduction
Bjarne Stroustrup presents C++ to the Founding Fathers
Things you need to know
Do I look like your mother?
- A few facts that you must know to survive in this class:
- Pressing the “L” key in the slides toggles link underlining.
- E.g., Latin “exempli gratia”, literally, “free example”, means “for
example”.
- I.e., Latin “id est”, literally, “it is”, means “in other words”.
- Emit means “produce”. Fires emit smoke.
Emit ≠ omit.
- ISO 8601 says that 2024‒11‒22 means November 22, 2024.
- Learn to read documentation: if, getopt(), cp.
- Avoid Canvas messages & submission comments. Send email.
- Don’t send images in your font/colors.
Learn to copy & paste text.
- 10:00:00ᴘᴍ MT Saturday means 10:00:00ᴘᴍ MT Saturday, not soon after. If that doesn’t
work for you, pretend that it’s due two hours earlier.
- If what you turn in doesn’t unpack and build, you get no
points.
- If it can be easily fixed, worked on your computer, you worked
really hard on it, and you need to pass for your scholarship:
still no points.
Origin
B-Strous
- 1979: Bjarne Stroustrup, at AT&T Bell Labs,
began work on “C with classes”.
- 1983: “C with classes” was renamed as “C++”.
- 1998: C++ first standardized by ISO.
Dialects
- In this class, we’re learning C++, not g++.
- g++ is the particular implementation of C++ that we use in class.
- There are other C++ compilers: Clang, Microsoft Visual Studio, etc.
- Similarly, there are many dialects of English, Spanish, French, etc.
Standards
- What is valid C++? Certainly,
int x=0;
is.
How about auto Δ=[](){};
?
- How do we tell what’s real C++ and what’s a dialect?
- How do know anything ?
- Definitions are by consensus.
“Dog” means 🐕 because we agree on that.
- Says who? Mom? Your next-door neighbor? The President?
The loudest person?
- An authority: a dictionary, the law, a committee,
scholarly consensus, an influential leader, etc.
Authorities
The important part is not the answer, it’s the “Says who?”.
Who’s the best pop singer?
- Beyoncé, according to … the BeyHive.
When is the holiday Washington’s Birthday?
- The third Monday in February, according to … the United States Congress.
Is Pluto a planet?
- No, according to … the International Astronomical Union.
How long is a meter?
- 1⁄299792458 light-second, according to …
the International Standards Organization.
Standard C++
- C++ is defined by ISO,
the International Organization for Standardization (?),
and its national member organizations such as ANSI,
the American National Standards Institute.
- There are several versions of the C++ standard:
1998, 2003, 2011, 2014, 2017, 2020.
- This class focuses on C++ 2017 (alias C++17).
- It’s too soon for C++ 2020.
- I’ll let you get away with anything that g++ permits on the
Linux lab computers, however.
- g++ implements extensions to the C++ standards.
- Handy, but dangerous. It’s easy to produce non-standard code.
- For almost everything that you turn in, you will provide
a control file (
CMakeLists.txt
or a Makefile
) that can
determine which version of C++ you want to use, via a g++ option.
Specify the version that you want to use.
- For other situations, assume C++ 2017.
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.
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.270142311%
of C programs are valid C++.
C++, not C
This is a valid C program, but not a C++ program,
because C++ claimed class as a keyword:
int main() {
int class=0;
printf("C: %d\n", class);
return 0;
}
C: 0
int main() {
int class=0;
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
- Despite all that, I don’t let you use certain C facilities
(printf(), malloc(), etc.) in this class.
- You must use the corresponding C++ facilities (cout, new).
- I feel no guilt about this.
- You’re too comfortable with printf(), so, if it were up to you,
you’d never bother to learn cout.
- It’s like removing the training wheels from your kid’s bicycle.