Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C/C++

The End of a Beautiful Friendship


Aug03: C Programming

Al is DDJ's senior contributing editor. He can be contacted at [email protected].


This issue marks my 15-year anniversary writing this column. It's been a long and fulfilling endeavor and probably the happiest job I ever had—with the possible exception of a two-month gig at age 18 playing piano in a strip joint in Washington, DC. More about that later. But the news this month is that, after 15 years, I am retiring the "C Programming" column. Or, more precisely, I am retiring from writing the column. I'll gladly pass the baton if anyone is adventurous enough to want it. More about my retirement later, too, but first there's one technical loose end to tie up.

I'm Confessin'

Over the past months, I identified some Standard C++ features, such as typename and name-dependent (Koenig) lookup, that the existing literature did not address adequately. I enjoyed pointing out those deficiencies as a way to plug my book, which covers the features. Since then, readers and authors alike told me about works that do explain those things, but the topics are not even mentioned by most books that claim to provide comprehensive coverage of Standard C++.

Now it's time for a confession. My book does not mention, except in the list of keywords, the Standard C++ export keyword. I have a lame excuse. None of the compilers in my development lab implement export. Consequently, there is no way I can test code that uses it to see if I even understand it properly much less whether I can explain it. I'll try, though, if only to close that one remaining hole in my contribution to the C++ teaching and learning culture.

The export keyword supports templates. Here's the problem it addresses. A template is essentially and traditionally a big old macro parameterized on data types. When you define a template, you write the macro. When you instantiate an object of a template class or define a template function, you invoke the macro, and the compiler generates code that expands the macro based on the type arguments to the template's parameters. The complete template source code must, therefore, be visible in a header file that the using program includes. If you instantiate a template object or function with an int argument, for example, the compiler generates all the source code that implements the template for an int. The template's member functions, which are given mangled names based on the arguments, are instantiated as static member functions in the translation unit, because if another translation unit in the same linked program uses the same template with the same argument, the compiler compiles copies of the same member functions for that other translation unit. If the functions were not static, their names would collide during the link pass. If the translation unit does not find all member functions declared somewhere visible to the translation unit, the compiler cannot build parameterized member functions and, therefore, cannot resolve calls to them.

The consequence of this technique is that, given traditional linker technology, a linked program that uses the same template instantiations in different translation units bears the burden of multiple copies of the template function code. Is it any wonder that programs compiled with the Standard C++ IOStreams library are much larger than the same source code compiled with the legacy IOStreams library? The former is based on templates; the latter is not.

A smart linker could observe multiple copies of the same template member function code and discard duplicates. I do not know whether contemporary compilers use such smart linkers though. This is where the export keyword comes in. It tells the compiler that a template function or class template member function is defined somewhere other than in the translation unit that declares the function. The compiler system defers instantiation of the template member functions, figuring they will be compiled by another translation unit and that their names will be resolved at link time.

To illustrate, consider Example 1. The doit.h file declares a template function named doit qualified with the export keyword to tell the compiler that the function definition is given elsewhere—in this case, in doit.cpp in Example 2. Observe that the definition also uses the export keyword to tell the compiler that this function is exported to be used by other translation units. Example 3 is a program that uses the doit template with two data types.

If my code has errors or my explanation is flawed, please blame another author who shall remain nameless. I learned how to use export from a book that does explain it. Except that I have no way to test the code. This is a heck of a way to make my departure—with untested code that even I don't understand. Somehow, though, the irony of the situation pleases me, and I'll leave it that way. My successor can fix it.

Ol' Rockin' Chair's Got Me

Enough of this technical stuff. Fifteen years is a long time. It's almost one quarter of my life. It's more than one third of the span of my career with computers. It's also the longest period of time I've maintained one assignment or job. I think that's because I've always worked about 3000 miles away from the bosses, and they haven't really gotten to know what a cantankerous fellow I can be. Telecommuting is a good operating model when you are a recognized curmudgeon.

I won't bore you with a technical retrospective of the "C Programming" column since August, 1988. If you are interested in the directions we've taken and the paths we've explored, you will find a compilation of the columns and other articles I've written for DDJ in the archives of the CD14 CD-ROM available from http://store.yahoo.com/ddjcdroms/.

I Could Write a Book

I once considered putting a collection of the columns and projects in a book. My publisher was interested in the idea, and it seemed like a quick and easy way to get yet another book in print. After all, the technical work was already completed. I abandoned the notion when I realized that many of the past "C Programming" projects are technically obsolete and interesting only from an historical perspective, and some would not even compile with contemporary compilers or run on contemporary operating systems. Not to mention how embarrassing some of my earliest C++ code is.

Bidin' My Time

Several converging circumstances brought me to the end of this era. One is that I'm happily stuck in a programming rut. To remain relevant and informative, an ongoing column such as this one should advance with the trends of technology. I did that once when I made the switch from C to C++ many years back, and, although the transition had me kicking and screaming, I never regretted making it. But I'm kind of mired down there. I successfully sidestepped Java and C# because I found nothing about them to interest me. Not that newer languages wouldn't be interesting to others. It's just that there is nothing I want to do with a computer that I can't already do with existing programs or by writing my own C++ code. And whereas I might enjoy reading about new development architectures, I am no longer up for the kicking and screaming. I cannot in good conscience abuse the privilege of this space every month by holding you readers back. I haven't written everything there is to write about C++, but I've said all I have to say.

If you want to know all I have to say about C++, buy a copy of Wiley's Teach Yourself C++, Seventh Edition, my final book on the subject. Other than a lack of any discussion on the aforementioned export keyword, the book covers the language from a tutorial perspective about as well as any I've seen. Thank you for putting up with what will have to be the last of my many shameless book plugs.

My Favorite Things

Over the years, I seldom used this column to endorse or review commercial software applications, but, since I'm leaving, I thought I would tell you about a few programs I find useful and will continue to use. Let me begin by saying that if I never had to turn on another computer, I might be a happy fellow. But there's no way that could ever happen. Music is the biggest part of my days (and nights) now, and computers are essential to music production. There are some programs I use routinely. I won't supply you with lists of features or criticisms except to say that these are the programs I use.

For musical notation, I use Noteworthy Composer (http://www.noteworthysoftware .com/), although its lack of support for transposing chord symbols has me looking for an acceptable alternative.

I use an indispensable audio transcription tool that I've mentioned here before. It's name is Transcribe! (http://www .seventhstring.demon.co.uk/) and, having found it, I cannot live without it.

For sequencing audio and MIDI projects, there is none better than Sonar (http://www.cakewalk.com/Products/SONAR/).

For processing raw audio, Cool Edit Pro (http://www.syntrillium.com/) is my application of choice.

I occasionally use Band In A Box (http://www.pgmusic.com/), an accompaniment generator, and frequently use MidiFitz, a program I wrote for real-time accompaniment. I introduced it in this column several years ago. MidiFitz reads the 88-key electronic MIDI keyboard, parses chords that the pianist plays, and plays drums and bass accompaniment in real time. I use it to practice in the studio. MidiFitz was a commercial program for a while and sold well, but software synthesizers have become the dominant default MIDI-playback devices on PCs, and their playback latency makes them unsuitable for real-time accompaniment. Tech support became impossible. Getting MidiFitz to work with newer operating systems required some tweaking that was beyond the comprehension of the average piano player, and without replacing the Windows default MIDI synth with something faster, it was not possible at all. I have placed MidiFitz online as an unsupported giveaway download. If you are interested, check http://www.alstevens.com/midifitz/. MidiFitz is now available with source code under a free software distribution model named "careware," which this column pioneered many years ago.

Some people have asked if I will continue to write programs. Unless something really compelling comes along, I will program only to develop applications I need for myself and then only if a search fails to turn up something suitable. I'll continue to use the gcc compiler suite and my own Quincy development environment (http://www.alstevens.com/quincy.html). When I work with source code written by other programmers, I use a program named Artistic Style (http://sourceforge.net/ projects/astyle/), an open-source code beautifier that I integrated into Quincy's toolset. I like Artistic Style because you can modify its source code to make it construct your own code-indenting styles. I also like it because it uses a command-line interface, making it easy to integrate into development environments such as Quincy.

I Wanna Be a Side Man

I'll continue to work as a contributing editor for DDJ, which means I get to edit all the articles and might write an article myself every now and then. But mostly, I'll do what I've always wanted to do for a living, which is what I was doing when I fell into this line of work—I'll be playing the piano in saloons. If you want to know where, check my web site at http://www.alstevens.com/.

I became a computer programmer because I wanted to be a musician. When I graduated from high school, I applied for a day job at the CIA driving a car around Washington, DC. My plans were to use that mindless job to pay the rent and buy groceries while I gigged at night, trying to get established as a jazz musician. You needed a security clearance to drive a CIA car, and that took a couple of months. At age 18, I'd never been anywhere or done anything that would compromise my integrity as a car-driving spook, so the clearance was a shoo-in. But I needed employment until I was fully investigated and blessed by the feds to carry those mysterious pouches and documents around town. To bide me over, I found a gig at the Players Club on 18th and K, NW. I played an old upright piano in a trio with two old guys—a drummer and tenor sax player. We pounded out those gravelly bump and grind tunes while some very nice ladies bumped and ground on the runway. By the time the clearance came in, my integrity had been compromised a couple of times, but the agency didn't seem to mind. They weren't really looking for drivers, though. They gave me a battery of tests and sent me to IBM 650 programming school. I kind of liked it, almost as much as playing the piano in strip joints, but the agency told me to quit that particular night job. They didn't say why. I went back to 18th and K a couple of years ago. The Players Club is gone.

I'm Gonna Sit Right Down and Write Myself a Letter

The e-mail address at the bottom of the first page of this column will still work for a while, but, being a public address, it has found its way onto every spam list that wants to offer me lower interest rates, herbal Viagra, digital-cable descramblers, ways to decrease my weight and increase other dimensions, opportunities to watch people doing things more commonly done in private, and so on. Eventually, I'll have to shut down the e-mail address just to stifle the spam.

Just Friends

This job has had many rewards, but the most precious of those are the friendships I formed among the staff at DDJ. The list includes Kent Porter, Monica Berg, Janna Custer, Peter Hutchinson, Deirdre Blake, Mike Swaine, Jeff Duntemann, Tami Zemel, John Dorsey, Ray Valdez, and, most of all, Jon Erickson, who, for some unfathomable reason, always let me write whatever I wanted to write, whether or not it had much to do with programming.

I also owe a lot to the software and book vendors who kept my technical library well stocked with all the latest computer books and programs. They made sure that I never ran out of things to write about. (You can stop sending me that stuff now.) And, finally, there are the countless readers whose encouragement, criticism, and loyalty made this job such a pleasant one.

On the Road Again

Being an itinerant piano player, I'll be on the road a lot. Some of you remember the Dobbsmobile, the RV in which Judy and I traveled for several years in pursuit of column fodder. There's a few miles left in the old bucket, and she is about to be recommissioned as a gigmobile. But they tell me that if I scrape off the DDJ logo, it will leave telltale marks, so she retains the insignia of the trusty old Dobbsmobile. Only now, she's taking Judy and me to places where they need piano players. Honk when you see us drive by.

DDJ


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.