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++

C Programming


AUG95: C PROGRAMMING

Grumpy Old Programmers

This issue marks the seventh anniversary of my first "C Programming" column. I went back and read that first column of August 1988 and saw that I promised then to report an occasional pet programming peeve. I did for a while, but eventually that part of the column faded away. I thought I'd use this anniversary issue to get a few things off my chest, so here are some rambling crotchets for you to peruse.

Have you noticed lately that the non-programming-industry press and the marketers have appropriated another of our buzz phrases? According to PC Magazine, the user interfaces of Windows 95 and OS/2 Warp are object oriented. Wow. That must make them better than all those other user interfaces that aren't object oriented. I've been sitting here at my Windows 95 Final Beta site trying to encapsulate something. I haven't figured out how, yet. The polymorphism command button must be in here somewhere, too, but I can't find it.

Here's how it goes. A paradigm such as object-oriented programming gains widespread acceptance. The market follows with tools that support that paradigm. It is good. Other products, unrelated to the paradigm, innocently use some of the same terms. Things on the GUI desktop, for example, are called "objects." Everybody knows that objects are good and that object-oriented anything is the wave of the future. Nontechnical journalists make the association, draw an invalid conclusion, saturate the print media with misinformation, and convert what was a perfectly good technical term into meaningless media hype. They have even said that Visual Basic is object oriented. When a programmer writes anything, an editor gets to have at it. An editor who writes something about programming should likewise be required to show it to a programmer, who should be given total veto power over the technobabble.

Remember some 20+ years ago, when the 12 rules of a relational database were developed? Every programmer knew what a relational database was until the subject was totally confused by the trade press reporting and marketing all those database products that claimed to be relational.

How about structured programming? The original definition specified three programming constructs: sequence, selection, and iteration. Simple and elegant. Yet every programming practice that someone has since disapproved of is criticized as not being structured enough, and tomes have been written on the subject of structured programming, addressing everything except those three simple statement flow constructs.

A Saturday Date

I am going to retire into obscurity on December 24, 1999. I advise you to do the same. One week later, all programmers will have the same respect paid to them that is now reserved for lawyers, politicians, and TV evangelists. On January 1, 2000, computer programs everywhere will cease to work properly because of the dreaded 6-digit date format. It isn't going to be a pretty sight. I don't want to be associated with the profession when the year 00 comes around. Some of it is my fault. I was one of those Cobol programmers in the 1960s who was sure that none of those programs and databases would last for 30-odd years. Hah! A lot of programs will need to be fixed, and a lot of databases will need to be repaired, come the new century. The largest impact will be on programs that support the government and business communities. That's lucky. January 1, 2000 is a Saturday. The New Year's Day holiday will be observed on Monday. They can fix the problem over the long weekend.

Memory Lane

I have a 486/66 with 24 MB of RAM. Every driver is loaded high. DOS is in the High Memory Area. XMS is enabled. How come programs such as Turbo Debugger still tell me I don't have enough memory?

Née IMail

It's hard to come up with a program name that no one has already used. Several years ago I picked D-Flat because I was sure that if I used C-Sharp, somebody's lawyer would come calling. D-Flat seems to have endured. My Quincy interpreter was originally named "QC," a name that lasted for only about two weeks. There already was a QC compiler, and its vendor hollered.

Now it has happened again. A while back, I launched a new column project, an Internet mail-reader program that I carelessly named "IMail." A call came in from Ipswitch Inc. (81 Hartwell Ave., Lexington, MA 02173), which produces a Windows-based Internet mail-reader program with the trademarked name--you guessed it--IMail. So now I have to come up with a new name.

I have to think of something so unlikely that nobody else would want it. That's why D-Flat worked. Butthead-mail has a certain ring. Nobody is likely to have used that one. Feminists might like Mail-Chauvinist. The logo could be a razorback in a mailperson's uniform.

Once I come up with a new name, I'll have to make some minor code changes and release another version. That's convenient, because a reader sent me a mail message about a bug. My scripting scheme of sending cat $MAIL followed by rm $MAIL has an insidious problem. If mail comes in while the cat command is running, the rm command will delete the new mail. That didn't happen during testing, but his message unearthed another silly bug. There was a dollar sign in the first column of one of his lines of text. The script program interpreted it as a UNIX prompt and stopped the reception. I'll be fixing those problems at the same time I find a new name.

GNU C++

Enough of this grousing. Late last year I wrote a fourth edition to a tutorial book on C++. It is called Teach Yourself C++, and, as I must remind you each time I plug this book, mine has a yellow cover and does not have Herb Schildt's name emblazoned on it. The book has many exercise programs and comes with a diskette with all the source. It seemed fitting that the book would round out a trilogy. I have a tutorial book on programming named Welcome to Programming, which uses QBasic as the teaching language, and one on C named Al Stevens Teaches C, which includes the Quincy C interpreter. If the C++ book could also include a compiler on its diskette, the trilogy would be complete--three books that take the reader from QBasic through C to C++ complete with source code and a language translator. (QBasic is included with every copy of MS-DOS.)

When you are looking for a contemporary C++ compiler that you may freely distribute without royalties and that implements most of the language, there is only one choice: GNU C++.

GNU C++, called "GPP," is the work of the Free Software Foundation (FSF). It is one of a large suite of free programming tools and utilities downloadable from many online locations and available on several commercial CD-ROMs. Anyone can distribute GNU software and charge reasonable copy costs as long as they include the source code or make it available to the user. (One such source is the Dr. Dobb's Alternative Programming Languages CD-ROM.)

I needed a version of GPP that runs under MS-DOS. Like other C++ compilers, GPP is a big program and needs a DOS extender. A version named "DJGPP" is distributed on CD-ROM by the FSF, and includes a DOS extender and C and C++ compilers that compile 32-bit programs. There is an assembler, linker, debugger, and other tools. To fit what I needed on a diskette, I had to strip down to the bare-minimum configuration--the C++ compiler, the linker, the assembler, the DOS extender, and only the basic run-time libraries and header files. Using LHARC compression, I was able to fit everything I needed to compile and execute all the exercise programs onto one high-density diskette.

We can discuss three things about DJGPP: the C++ compiler, the DJGPP port to MS-DOS, and the CD-ROM products that FSF sells.

GPP is a contemporary C++ compiler that implements the version of C++ described in the Annotated C++ Reference Manual, by Margaret A. Ellis and Bjarne Stroustrup (Addison-Wesley, 1990). The only feature not yet implemented is exception handling. GPP does not implement run-time type information and newstyle casts or the other new language inventions of the ANSI committee. Of the 150 exercises in the book, only a dozen of them involve language features not implemented by GPP, so the book is a minor torture test for the compiler. I found a few bugs related to the translation of invalid code but only one bug where the compiler failed to work at all. Any program that includes iomanip.h and uses the setw manipulator does not compile. That's a serious problem. I reported it to the GPP developers, and it should be fixed in a future version. Example 1(a) is a program that won't compile under GPP.

To circumvent the problem, I inserted the code in Example 1(b) into the smanip class-template declaration in iomanip.h. This workaround generates several warning messages, but the code compiles now, and the program runs okay.

GPP is not the fastest C++ compiler available, nor does it generate the most optimized executables, but you can't beat the price. The GNU suite of software puts quality tools well within the reach of educators and, more importantly, students of limited means. Having the source code to the compiler lets you use GPP both as a study in compiler design and to implement and experiment with language features. It would be fun to implement Visual GPP, for example. The compiler source code is not easy to read. They used a grammar and a yacc clone. You have to get into that mindset if you want to make changes to the language. You should anyway, if you are going to experiment with language translation.

DJGPP

The DJGPP port of GNU C++ includes extended DOS executables for the compiler programs as well as the header files and libraries to support development of extended DOS programs of your own. To run DJGPP or a program that you compile with DJGPP, you must have a program named GO32.EXE in the path. That program is the DOS extender. If you are running programs that use floating-point math on a PC without a math coprocessor, you need a file named EMU387 in the path in order to emulate the coprocessor. If you distribute programs compiled with DJGPP, you must also distribute these files.

The FSF Compiler Tools Binaries CD-ROM

The Free Software Foundation distributes DJGPP on their Compiler Tools Binaries CD-ROM. It costs $240.00 for companies and $60.00 for individuals. It includes GNU C and C++ compilers and many utility programs to run under MS-DOS and other platforms that do not come with compilers. The CD-ROM includes the source code for all programs on the CD-ROM.

The CD-ROM includes installation instructions to run the compiler from the CD-ROM. You make sure that the path is set up correctly, set some environment variables, and that's it. Nothing gets copied to the hard disk. You do not want to do this, however, unless you are really short on disk space and have at least a quad-speed CD-ROM with caching software installed. When running from the CD-ROM, the program in Example 2 takes four minutes to compile and link on a 486/33 with a single-speed CD-ROM drive. By installing the compiler on the hard disk, I reduced that time to 15 seconds.

Depending on how much of the compiler system you want to install on your hard disk, DJGPP can require 7-160 MB.

Installation on a hard disk is not as easy as installing to use the compiler from the CD-ROM. You have to poke around in the CD-ROM and find all the different README files to get the complete picture. Installation consists mainly of unzipping several compressed files in a specific sequence and then doing the same path and environment-variable manipulations that you would with the CD-ROM.

Documentation comes in text files formatted for a reader program that comes with the package. Most MS-DOS programmers will not like this program. Its user interface is less than intuitive for those used to CUA programs. The reader program also does not work with all keyboards. The program does not use standard BIOS calls to read paging and scrolling keystroke values. Two PCs in my shop can't get past the first screen.

There is a decided UNIX text-mode feel to the FSF Compiler Tools CD-ROM. Don't expect slick, GUI-hosted editor/debuggers and utility programs or greased installations. You have to be a programmer to use this product, and you have to be a programmer to find the stuff that you need to use this product. You don't simply run a command-line compiler and get an executable. The command-line compiler does not automatically find standard libraries; you have to specify them on the command line. Output from the compiler/ link procedure is always to a file named a.out, which is not ready for execution. You must postprocess this file through two more programs to get an executable file, which you must then rename to whatever .EXE file you want. The compiler does not produce a menu of command-line options or even a version number when you enter only the compiler's name on the command line.

Those few criticisms notwithstanding, GNU C++ and the DJGPP port are powerful products and well worth their nominal cost. In today's market, sixty bucks is not a lot for a text-mode-only, command-line-driven C++ compiler, even when you buy it from an organization dedicated to the promotion of free software.

ANSI C++ Public Review

If you act fast, you can get your two cents worth into the C++ standardization effort. In late May, I received an announcement stating that the X3J16 committee will conduct a two-month public review of the draft standard for C++. The review lasts from May 26, 1995 to July 25, 1995, but the committee must receive your written comments by July 6 to consider them in their current deliberations. They'd like e-mail in advance ([email protected]) but require signed hardcopy before they can register your comments.

I am able to report this event in the August issue because many of you get the issue at the beginning of July. With luck you have about a week to get a copy of the draft, read it cover-to-cover, and send in your comments. Send $65.00 to X3 Secretariat, Attn: Lynn Barra, 1250 Eye Street, Suite 200, Washington, DC 20005, 202-626-5738. I wish I could give you more time, but this is all the time they allow.

Example 1: (a) A program that won't compile under GPP; (b) inserting this code into the smanip class-template declaration in iomanip.h circumvents the problem.

(a)
#include <iostream.h>
#include <iomanip.h>
main()
{
  cout << setw(6) << "hello";
}
(b)
friend
  ostream& operator<<(ostream& o,
 smanip<TP>& m)
    { (*m._f)(o, m._a); return o;}
Example 2: This program takes four minutes to compile and link on a 486/33 with a single-speed CD-ROM drive. Installing the compiler on the hard disk reduces the time to 15 seconds.

#include <iostream.h>
int main()
{
   cout << "hello";
}


Copyright © 1995, Dr. Dobb's Journal


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.