ARTLUNG
personal website: joe crawford. code. occasional comics. toy robots. bodysurfing. san diego. california. say hi.
since 1998

Hard Drive Cleaning: C++ Programming ’04

In 2004 I took a course at City College in C++ Programming. As I wait for my new job to start next week I’ve been doing a bunch of maintenance. I found an old backup hard drive and found a folder called cpp from an old Windows machine I had. I think it was running Windows NT? Anyway, here’s a program!

#include <iomanip>
#include <iostream>

using namespace std;

int main()
{

	int intNum = 111;
	int &refIntNum = intNum;

	cout << "intNum is " << intNum << endl;
	cout << "refIntNum is " << refIntNum << endl;
	cout << "The memory address of intNum is " << &refIntNum << endl;

	int intNum2;
	int &refIntNum2 = intNum2;
	intNum2 = 222;

	cout << "intNum2 is " << intNum2 << endl;
	cout << "refIntNum2 is " << refIntNum2 << endl;
	cout << "The memory address of intNum2 is " << &refIntNum2 << endl;

	int intNum3;
	int &refIntNum3 = intNum3;
	intNum3 = 333;

	cout << "intNum3 is " << intNum3 << endl;
	cout << "refIntNum3 is " << refIntNum3 << endl;
	cout << "The memory address of intNum3 is " << &refIntNum3 << endl;
 
	return 0;
}

Definitely a kind of Hello World program possibly from a lecture. I don’t think I have notes from that class at City College anymore. But it was a solid class.

C++ programs are of course compiled. I tried initially on my current Mac (a 2013 machine running the latest MacOS Big Sur) to run cpp Hello.cpp

# 1 "Hello.cpp"
# 1 "" 1
# 1 "" 3
# 367 "" 3
# 1 "" 1
# 1 "" 2
# 1 "Hello.cpp" 2
Hello.cpp:1:10: fatal error: 'iomanip' file not found
 
         ^~~~~~~~~
....
1 error generated.

Now, iomanip is present on this Mac. It’s at /Library/Developer/CommandLineTools/usr/include/c++/v1/ but I was using the wrong compiler command. I needed to run g++ Hello.cpp. That command dutifully compiles. How do we know it compiles? Because of course it doesn’t seem to do anything when we run it on the command line! But there is now a file called a.out in the directory. And when we invoke it in the Terminal.app in that directory by doing ./a.out we get output!

intNum is 111
refIntNum is 111
The memory address of intNum is 0x7ffee88cf238
intNum2 is 222
refIntNum2 is 222
The memory address of intNum2 is 0x7ffee88cf22c
intNum3 is 333
refIntNum3 is 333
The memory address of intNum3 is 0x7ffee88cf21c

It’s kind of an amazing accomplishment that this rather old infrastructure for programming in C++ is built into my machine and I didn’t have to install anything on a completely new machine to compile it. When I think about the relative complexity of getting a random current JavaScript project to run, what with inevitable updates to npm, wow.


posted this 10 months ago.
What else did he post in February 2022?

(Thursday February 17th 2022 at 8:27am)

Leave me a comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.