Columns


C/C++ Sources

by Victor R. Volkman


Introducing C/C++ Sources

Welcome to the first installment of my bimonthly “C/C++ Sources” column. Longtime readers of CUJ may remember my previous column, “C Users Group New Releases” which ran from 1993 to 1995. Whereas CUG New Releases focused solely on the CUG Library collection, this column will tell you about shareware and freeware source code archives available in a variety of locations, including:

Although the focus is on C/C++ programming source libraries and tools, Ill also highlight other products that include C/C++ code with them or include code upon registration. If youre the author of such an archive, please write to me and Ill feature it in an upcoming column. Even if you just want to recommend a product, Id like to hear from you. Each month, one reader who has submitted a tip on an archive will receive a free shareware CD-ROM from me. This month, I present a special theme product (that is, a product that fits in with this issues theme, Cross-Platform Development) and a look at the GNU C/C++ suite.

Theme Product: MICRO-C

Dave Dunfield (Nepean, Ontario, Canada) supports an entire suite of C compiler tools from the MICRO-C development system. This includes the MICRO-C C compiler itself for MS-DOS, many sample C programs, and a demonstration version of MICRO-C for embedded systems. MICRO-C is a tiny compiler which can run with less than 32 KB of RAM and yet is highly independent of CPU and OS. Specifically, MICRO-C supports separately the 68HC08, 6809, 68HC11, 68HC16, 8051/52, 8080/8085, 80x86 and 8096 CPUs. MICRO-C also includes a fully functional MICRO-C compiler executable built for the MS-DOS 80x86 environment. This version generates code in .ASM format so Microsoft MASM, Borland TASM, or equivalent are required (not included). MICRO-C version 3.02 was released on 03/22/94.

MICRO-C provides much more functionality than Small-C and its many derivatives. Specifically, MICRO-C supports all C statements, operators, and preprocessor directives as well as inline assembly code. MICRO-C includes data types for int, char, unsigned, struct, union, pointers, and typecasting. Saying it another way, MICRO-C gives you everything possible except for typedef, long, double, float, enum, and bitfields. The runtime library does include a long arithmetic package with arbitrary precision up to 256 bits.

Even if youre not especially interested in the MICRO-C compiler, you may wish to take advantage of the collection of more than 70 sample programs. Although there are simply too many to catalog here, Ive listed sixteen of the most interesting:

CCREF — C source cross referencing program
OBSCUR — Make C program unreadable (but it still compiles)
CMOS — Read/Write/Verify CMOS RAM from/to/with disk file
CSET — TSR map of IBM PC character set
GREP — Like UNIX GREP search utility
HEM — Hardware Exception Monitor TSR to trap unexpected interrupts
LZC — Laser commander TSR to control HP-compatible printers
MTERM — Tiny (10 KB!) TSR ANSI terminal with XMODEM
TFB — TSR File Browser
VALIDATE — Verify files with two CRCs, like McCaffee
LAPTALK — A terminal program with script interpreter
XMODEM — External file-transfer program
MICROCAD — Mouse-based drawing program
FE — Font Editor
ASM86 — 8086 assembler
BASIC — A simple BASIC interpreter
DIS85 — 8085 Cross Disassembler
TTT3D — three-dimensional tic-tac-toe

All files in the MICRO-C archives are for personal use only. Any commercial use of information or programs contained in these archives requires written permission from Dunfield Development Systems. You can obtain source code separately for the MICRO-C compiler by purchasing a license for $100 from DDS.

Where to Get MICRO-C

MICRO-C is available on the SimTel FTP server on the Internet (and its mirrors), CUG Library, HAL 9000 BBS, and the Walnut Creek SimTel CD-ROM. The primary FTP site for SimTel is ftp.coast.net:/SimTel/msdos/c. WWW users may access the URL http://www.acs.oakland.edu/oak/. You may access it via Gopher client to Gopher.Oakland.Edu.

Please use an alternate mirror site to save bandwidth, if it is closer to you. Heres an abbreviated list of SimTel mirror sites to get you started:

Location    Server
Switzerland nic.switch.ch:/mirror/simtel/msdos/c
Japan       ftp.iij.ad.jp:/pub/msdos/c
U.K.        micros.hensa.ac.uk:/mirrors/simtel/msdos/c
Brazil      ftp.unicamp.br:/pub/simtel/msdos/c

MICRO-C products (and associated filenames) featured in this issue are as follows:

Filename      Description                               Size
MC302EMB.ZIP  MICRO-C embedded control — Test Drive     213KB       
MC302PC1.ZIP  MICRO-C PC C compiler (fully functional)  194KB     
MC302PC2.ZIP  Over 70 example MICRO-C programs          276KB

MICRO-C is available on diskette from the CUG Library for $19.50, contact rdorders@rdpub.com or call (913) 841-1631 to order. You may also download it from the HAL 9000 BBS, call (313)663-4173, v.34/V.FC 28,800bps or telnet/rlogin to hal9k.com.

The Walnut Creek SimTel CD-ROM is a two-volume set of utilities, programming tools, source code, technical documentation, etc. The current edition was made in September 1994 and is MS-DOS BBS ready. This disk is available by quarterly subscription for $19.95 per issue plus appropriate shipping. The single-issue price for this two-disk set is $34.95. To order, call (800)786-9907 or email to orders@cdrom.com.

A New Look at GNU

The GNU project, brainchild of the Free Software Foundation (FSF), is one of the software industrys best kept secrets. GNU, a recursive acronymn which stands for “GNUs Not UNIX,” focuses primarily on providing enhanced versions of UNIX programs and libraries. All GNU programs include complete source and a special license for redistribution. The cornerstone of the GNU project is the GNU C/C++ compiler and library (better known as g++ and libg++). Though GNU undoubtedly deserves book-length treatment, the remainder of this column provides only a brief overview of the C/C++ compiler and some related tools.

The g++ Compiler

The GNU g++ compiler has been acknowledged by many users as one of the best compilers and is used in production mode at many commercial software houses. It certainly ranks as the most portable compiler in the world; it has support on every significant platform including the following:

And many others!

Using the built-in configuration scheme, you can build cross-compiler combinations as well. This feature is extremely useful when building executables for embedded systems that may not have sufficient OS capability to host compilation.

The GNU g++ compiler supports multiple languages through the choice of compiler option or file extension (e.g. “.cpp” for C++). The standard distribution includes support for C, C++, and Objective-C (courtesy of NeXT). The g++ compiler now tracks the evolving draft ANSI standard rather than the archaic AT&T CFront compiler.

The g++ system supports full ANSI C, traditional C, as well as the GNU extensions. In the GNU tradition of providing more than just emulation, the GNU extensions include support for nested functions, nonlocal gotos, and taking the address of a label.

The g++ compiler can perform a full suite of optimizations including hoisting invariant code out of loops, instruction scheduling, loop unrolling, common subexpression elimination, tail recursion eliminination, and many other optimizations too numerous to list.

The g++ Runtime Libraries

The runtime library is an integral part of any C/C++ compiler implementation. In keeping with the C/C++ conventions, the GNU C Library and GNU C++ Library (libg++) are quite distinct entities of their own. As such, Ill provide specific details on each.

The GNU C library supports ANSI C-1989, POSIX 1003.1-1990, and most of the functions in POSIX 1003.2-1992. GNUC is upwardly compatible with 4.4BSD and includes many System V functions, plus GNU extensions. The GNU stdio library lets you define new kinds of streams by writing a few user-defined C functions. For example, fmemopen uses this capability to open a stream on a string which can dynamically grow. You can define your own printf formats to use a C function you have written.

The GNU C++ library (libg++) contains an extensive collection of C++ “forest” classes, an IOStream library, and support tools. Supported classes include: object stacks, multiple-precision integers and rational numbers, complex numbers, arbitrary length strings, BitSets, and BitStrings. GNU libg++ now supplies the libstdc++ library defined by the ANSI/ISO C++ draft standard, including the Standard Template Library (STL).

GDB The GNU Debugger

GDB enables source-level debugging for C, C++, and FORTRAN. GDB also works with executables produced by many different compilers. GDB can even use the symbol tables emitted by most MIPS-based compilers, including DEC. However, if you use C++ compilers other than g++ then debugging with GDB will entail some limitations. GDB supplies a command-line user interface. Alternately, you can run it from an EMACS or X-Windows interface (unsupported).

GDB uses the GNU Binary File Descriptor (BFD) library to read executable files and symbol tables. BFD allows a single version of GDB to debug programs with multiple object-file formats (such as COFF and ELF). GDB also offers a complete command language, remote debugging over serial ports or TCP/IP, and breakpoints on expressions (a.k.a. watchpoints). Additionally, GDB can use a standard remote interface to a library which can simulate the Zilog Z8001/2, Hitachi H8/300, H8/500, and Super-H microprocessors.

GDB can perform some cross-debugging. Platforms supported in target mode can perform native or cross-debugging; platforms supported in host mode cannot necessarily debug native programs. The permutations of supported host and target modes are too numerous to list here.

D.J. Delories g++ System

D.J. Delorie has ported GNU C/C++ 2.6.0 and libraries to the Intel 80386 architecture for MS-DOS. Delorie also provides a 32-bit DOS extender (to run applications in Protected Mode), symbolic debugger, and even ports of Bison (GNU YACC), flex (GNU LEX), GAS (GNU Assembler), and Binutils (platform-independent binary file I/O). Collectively, this entire system is known as DJGPP.

As with all GNU products, DJGPP provides full source code. It supports SVGA (up to 1024x768 resolution), XMS & VDISK style memory allocation, HIMEM.SYS extended memory manager, VCPI (Virtual Control Program Interface used by QEMM, DESQview, and 386MAX), and DPMI (DOS Protected Mode Interface as used by Windows 3.x, OS/2, and QEMM). You may join the DJGPP users mailing list by sending your request to djgpp-request@sun.soe.clarkson.edu.

More Good GNUs

Of course, GNU provides more than just a great C/C++ compiler. In their quest towards a complete GNU-based OS, FSF (The Free Software Foundation) provides many more languages and utilities. Nearly all of them provide significant enhancements over their traditional UNIX counterparts. As of this writing there are nearly 100 separate packages offered by GNU, far more than can even be listed in this story.

Where to Get GNU

GNU software is available direct from the Free Software Foundation, by FTP over the Internet, or on Walnut Creek archive CD-ROMs. Portions of the GNU distribution also appear on the CUG Library CD-ROM. When you buy direct from the FSF, you help to financially support its continuing freeware projects. Alternately, you can get a free copy of GNU software and make a tax-deductible contribution to FSF. Of course, you are under no obligation to pay anything.

The primary GNU FTP site is prep.ai.mit.edu:/pub/gnu (Artificial Intelligence Department, Massachusettes Institute of Technology). The file /pub/gnu/DESCRIPTIONS provides a paragraph on each of the GNU products. Please use an alternate mirror site to save bandwidth, if it is closer to you. Heres an abbreviated list of GNU FTP mirror sites to get you started (complete list in /pub/gnu/GNUinfo/FTP):

Location    Server
Virginia    ftp.uu.net:/archive/systems/gnu
Australia   archie.au:/gnu
BC, Canada  ftp.cs.ubc.ca:/mirror2/gnu
Japan       utsun.s.u-tokyo.ac.jp:/ftpsync/prep
Switzerland nic.switch.ch:/mirror/gnu

GNU products (and associated filenames) featured in this issue are as follows:

Filename              Description              Size
gcc-2.7.0.tar.gz      GNU g++ (C/C++) v2.7.0   7.0 MB
libg++-2.7.0a.tar.gz  GNU C++ library v2.7.0a  1.6 MB
gdb-4.14.tar.gz       GNU Debugger v4.14       4.5 MB

Note that DJGPP is not an official FSF sponsored project so it is found instead on oak.oakland.edu:/SimTel/vendors/djgpp. The filenames on that server meet the MS-DOS 8.3 limitations and are in smaller pieces for easier downloading and disk copying. Note that DJGPP versions of g++ will always trail major releases by a few months. For example, the current DJGPP is version 2.6.2 as of this writing.

FSF refuses to use the standard UNIX “compress” utility for ideological reasons. Instead of compress, you are advised to use GNU gzip which actually achieves better reduction. You can recognize a gzipped file by its .gz extension. This is a totally different file format than used by PKZIP.

To extract sources that are in files ending in .tar.gz you can use the command

gzip -d < foo.tar.gz | tar xf -

where foo.tar.gz is the name of the file.

The Walnut Creek GNU CDROM contains the complete GNU software library, as well as binaries for both SunOS 4.1.3 and Solaris 2.3. This software is ready to be compiled on a great number of platforms, and includes such packages as Emacs 19.25 and gcc 2.6.0. This disc is in Rock Ridge format, so full UNIX pathnames are visible. This CD-ROM was last cut in August 1994 and costs $40 (add $5 S/H). To order, call (800)786-9907 or email to orders@cdrom.com.

GNU Resources

Many of the GNU products have their own mailing lists for interested users and co-developers. GNU has also established a complete hierarchy of Usenet newsgroups (Gnusgroups?). There is a “.bug” newsgroup for each of the major products (e.g. gnu.g++.bug for g++ problems). Heres a brief overview some of the nearly 50 newsgroups in the gnu.* hierarchy:

Newsgroup name    Description
gnu.announce      General announcements for GNU and FSF
gnu.bash GNU      Bourne-Again Shell (BASH)
gnu.emacs.*       Eleven newsgroups devoted to EMACS
gnu.g++.*         Six newsgroups about g++ (GNU C++)
gnu.gcc.*         Four newsgroups about GNU C
gnu.gdb.*         Two newsgroups about GDB
gnu.ghostscript.* Two newsgroups about GNU Postscript
gnu.misc          Miscellaneous announcements
gnu.misc.discuss  Discussion of above
gnu.smalltalk.*   Two newsgroups about GNU Smalltalk
gnu.test          Test for the GNU hierarchy
gnu.utils.*       Two newsgroups about UNIX type tools 

Victor R. Volkman received a BS in Computer Science from Michigan Technological University. He has been a frequent contributor to C/C++ Users Journal since 1987. He is currently employed as Senior Analyst at H.C.I.A. of Ann Arbor, Michigan. He can be reached by dial-in at the HAL 9000 BBS (313) 663-4173 or by Usenet mail to sysop@hal9k.com.