Dr. Dobb's Journal May 1997
Dear DDJ,
Poul Costinsky's letter in the March 1997 issue of DDJ claims to show a way to manually call constructors that's "100 percent portable, legal, and exhibits good style." It is none of these things.
The fundamental problem is that p->Foo::Foo() should not invoke the Foo constructor on the memory pointed to by p, it should fail to compile. This has been the case in C++ as long as I can remember, but it seems that many compilers still get this wrong: I tested Borland C++ 5.01, Visual C++ 4.2, and g++ 2.7.2, and only Borland correctly rejected the code. In fact, Borland's error message is both surprising and surprisingly accurate: It states that "Foo is not a member of Foo". This corresponds precisely to the wording in the draft C++ standard, which states that "constructors do not have names [and] they are never found during name lookup."
It is still possible to do what Poul wants to do, but the trick is not to call a constructor explicitly. It's to use "placement new," which is an indirect way of invoking a constructor on raw memory that is 100 percent portable and legal. Example 1 is Poul's code as it should be written. Note how the loop calling destructors counts down instead of up. This is necessary to satisfy the C++ rule that destructors are called in the inverse order of constructors.
Readers interested in this and related issues may wish to consult my book, More Effective C++, which shows how to do this and many other things in a safe and portable way. Book information and excerpts are available at http://www.aw.com/cp/mec++.html.
Scott Meyers
smeyers@netcom.com/
Dear DDJ,
As Al Stevens suggests in his February 1997 "C Programming" column, part of the mythology of the various NASA programs, which culminated in Apollo, is that although the computers of the various vehicles and launchers were advanced for the time (and more so than similar systems in the USSR), today they would be considered very primitive. Can he put this in perspective? How big was the Saturn flight computer, in terms of weight, size, memory (were the early ones really drum based?), power consumption, and backup storage? Did Apollo really go to the moon and back on 4 KB? I tried to find this information on the NASA web site but failed. I wonder if anyone can suggest a better site, or specific entry point to the site?
An idea I find intriguing is that, if production did start up again, could you get a performance boost by reengineering some of the various subsystems while keeping the main structure the same, even running the same software using the same instruction sets but on late-1990s hardware, avoiding a software rewrite and the necessary (and very expensive) retesting? It has, after all, already demonstrated it can do the job, although one or more higher clock speeds could be added for expansion (although Murphy's law suggests that it would be only a matter of time that the wrong chunk of software ran at the wrong speed).
On a more serious note. It is not particularly new that people tend to joke or be abusive about tragic incidents. Among workers in dangerous or potentially dangerous jobs (policemen, soldiers, test pilots), it is not uncommon as a way of dealing with almost overwhelming fear or anger at the unfairness of a situation. I think the earliest description of this is English longbowmen raising the middle and 4th fingers of their right hand (palms inward) to show the French enemy at Agincourt (who cut these fingers off captured bowmen) "I can still fight, I can still kill you." It is still considered an offensive gesture in the UK today.
Jokes may have become more widespread in society as a way of showing how "tough" people can be -- a response to the idea that the world has become a less caring place and you should not show you care -- the "be a man, not a wimp" attitude.
A greater degree of cynicism may also exist. I never understood the frantic desire to launch Challenger following bad weather, which turned out to have such a lethal serious effect on the section seals of the SRBs: a vital mission with a very short launch window, or the publicity stunt of an organization trying to salvage credibility? (Yes, I am aware of how simplistic and tabloid-like that choice appears.)
If you are inclined to the latter, a display of contempt for an organization that appeared ready to sacrifice seven people might seem quite reasonable. I believe it was Chuck Yeager (the first man to break Mach 1) who commented at the time that, basically, the U.S. space program had a pretty low body count. This stuff is still pretty risky whatever the public-relations people say, and if you want to be an astronaut you should be aware the ticket price maybe your life. Not quite the image of weekly trips into low earth orbit.
Steve Barrett
106313.2474@compuserve.com
Dear DDJ,
The tale of the new century happened to me yesterday. I tried to pay for an airline ticket with my newly arrived Eurocard (Master Card affiliate) for February of this year, which expires in 01/00.
What happened? The Master card verification computer refused the number, because it doesn't know about the year 2000 yet. Happily, I also have a Visa card that expires in March of this year, so at least I got my ticket!
A long-distance telephone call to Eurocard resulted in my being switched around on hold to five different people (at my expense, of course), until I got a nice lady who told me that their computer was rejecting all the new cards with expiration dates in the year 2000, and that they would send me one which expires in 1999 until they get things sorted out! That seemed to her to be simpler than trying to fix the program, I guess.
It just goes to show that you don't have to wait another couple of years for the fun to start! Maybe European time is just that wee bit ahead.
Irwin Scollar
al001@rs1.rrz.Uni-Koeln.DE
Dear DDJ,
I mostly enjoyed Alan Cooper's article on "Goal-Directed Software Design" (DDJ, September 1996). There is a great deal of software out there that seems to be written with the aim of loading as many features as the average systems will handle without considering the real needs of the likely user. I do take issue, however, with some of the items Alan considers to be "False Goals." For example, while memory is much cheaper, disk space more plentiful, and computers much faster than they were 20 (or even 10 years) ago, software has taken full advantage of this by taking more memory and disk space and running much less efficiently. Since a great many users can't afford to buy a new computer or upgrade their equipment every other year, developers still need to pay attention to things like memory, disk space, and speed.
Maintaining consistency across platforms is likewise more important than many developers (Microsoft, for example) seem to realize. For instance, I am typing this letter using Microsoft Word 6.0 for DOS, despite the fact that I am using a P90 under Windows 95, and Word 7.0 for Windows is also installed my machine. Why? DOS Word is faster, does everything I need it to, and WinWord is just different enough (even in where things are located in the pull-down menus) to be an irritant. Goals such as these are subordinate to enabling the user to accomplish something useful with the software without tearing his hair out and (in the case of commercial software) ensuring that the boss makes a decent profit -- but they still must be considered. A better term for such goals would be "implementation goals."
Thank you for including articles like Alan's (I also enjoyed the interview with Donald Knuth in April, 1996) and I hope you continue to run them. Understanding the general principles of computer science and good programming practice is far more important than understanding all of the ins-and-outs of the latest hot programming language or API.
John L. Ries
San Diego, California
Dear DDJ,
In the "Letters" section of the July 1996 issue, I noticed an ongoing debate about dates and correct calculations. L. Salinari mentions a shift of 10 days in October 1582 (Oct 4 = Thu, Oct 15 = Fri). As far as I know, such a shift only occurred in September of 1752 (Sep 2 = Wed, Sep 14 = Thu). I checked both months using the UNIX cal program, and it bears me out on September 1752; none show any unusual day shifts in October of 1582. Please, can we have someone go into the complete history of which calendar was in use when, how they worked leap years and month lengths, and so on. Of course, we would like some algorithms, too. I don't think I'm alone in being somewhat confused between Julian and Gregorian dates and calendars. Also, many applications convert a supplied date to an unsigned int and then call it a "Julian date."
Jan Kaluza
South Africa
jfk@paradigm.co.za
DDJ responds: Jan, "Julian and Gregorian Calendars," by Peter Meyer (DDJ, March 1993) provides an excellent discussion.
Dear DDJ,
I am compelled to compliment and thank you for printing the article "Examining the Windows NT Filesystem," by Mark Russinovich and Bryce Cogswell (DDJ, February 1997). I have been working on an application that will need to utilize API monitoring techniques, some of which involve file I/O. I was scratching my head, drinking a lot of coffee, and getting ready to bite the bullet and burn the midnight oil a few times until I read this article. Keep up the good work on this invaluable publication.
David Schraff
davidS@iotech.com
DDJ