I am compiling a program. It's not just any program: I wrote it in 1993 and I'm trying to compile it again now (2024).


  g++ myprogram_1993.cc -L/usr/X11R6/lib -lX11 
There are some small problems to take care of first. One of them is that it uses ".h" in the includes, and does not have "using namespace std;" both of which were the style at the time, like wearing an onion on your belt. Also "main" was type "void", so I made it "int" and added "return 0;" to it. The new version is "myprogram_1993b.cc".

Here's where it gets weird. Compiling it tells me "4 errors generated", but the amount of output from the compiler is staggering: about 470 lines. Here are the first relevant lines.


  myprogram_1993b.cc:500:21: error: invalid operands to binary expression ('ostream' and '__iom_t4')
         ofile << hex << setfill(48) << setw(2) << temp <<"  :";
         ~~~~~~~~~~~~ ^  ~~~~~~~~~~~
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ostream:800:1: note: candidate function template not viable: no known conversion from '__iom_t4' to 'char' for 2nd argument
  operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
  ^
The fix is actually trivial, but finding the problem was difficult. An on-line search did not help (which is why I'm putting this on-line). The problem is that 48 (the ASCII code for the digit zero) needs to be a character. So I made the following change.

  500c500
  <        ofile << hex << setfill(48) << setw(2) << temp <<"  :";
  ---
  >        ofile << hex << setfill('0') << setw(2) << temp <<"  :";
There were 3 other places in the code that needed to be changed, too, but after this, the program compiled and ran.




-Michael Weeks, November 23, 2024