The SNIPPETS C++ Source Code Archives
Tuesday, 13-May-2008, 21:36:01 GMT
Last modified: 22-Sep-2003, 21:48:22 GMT
83768 visitors since 14-Sep-2003
Archivist: Bob Stout
 |
Return to the SNIPPETS archives project |
Download the C++ archive in ZIP format |
 |
 |
Join the C++ programming mailing list |
 |
Browse the C++ code archives |
Support SNIPPETS |
 |
What is SNIPPETS?
The SNIPPETS collection started out in the late 1980's as a personal project to
collect useful snippets (hence the name) of C, and later C++, code which would be
free for reuse in a personal or commercial environment. Over time, it has grown
to more than 94,000 lines of code in over 700 separate files. The goal of
SNIPPETS is to collect and disseminate the best C/C++ answers to "How do I...?"
programming questions.
Although it hasn't been well maintained since 1997, this is changing as SNIPPETS
becomes primarily a web-based document. The first requirement for code to be
included in SNIPPETS is that it must be either public domain, freeware, or carry
a free use license. For further discussion of what makes code a candidate for
SNIPPETS, see the rationale. Also changing rapidly is
the fact that, previously most SNIPPETS code was tested on PC's under
DOS/Windows, whereas more and more is now tested under Linux.
Note that this web site could be significantly improved cosmetically by the use
of frames, Javascript, or other techniques. It exists as it is in order to be as
compatible as possible with every imaginable browser, including text-mode
browsers such as LYNX. To facilitate the downloading of only specific files of
interest, the navigation menus will open each SNIPPETS file in a separate browser
window, where it may be studied or easily copied.
The SNIPPETS C++ mailing list conference:
The SNIPPETS Archives Project for C++ exists to promote C++ education. It does this
with the publication of free code as well as an associated discussion conference.
Implemented as a lightly moderated Internet mailing list, the conference promotes
C++ education by three of the most effetive means possible:
- Bring togethers programmers of all experience levels so the beginners can
learn from experienced experts.
- One of the best ways to truly learn anything is to have to try to teach it to
someone else. Both beginners and the "gurus" alike can sharpen their skills by
joining in explanations. Sometimes, the perspective from a relative newcomer can
be invaluable in getting a point across to someone new.
- The best answer to almost any programming question is to post code! Since one
of the conference rules (see below) is that all posted code must be either
explicitly public domain or carry a free use license, the code each subscriber
posts becomes candidate code for the archives.
As a lightly moderated conference, the C++ conference has some rules. You can read
these at http://cpp.snippets.org/cpp-rules.html.
Subscribe at http://snippets.org/mailman/listinfo/cpp.
Portability:
One major change in this release is in the testing philosophy. In the past,
all SNIPPETS code was tested with PC compilers from Microsoft, Borland, Watcom,
and Symantec/Zortech, and where possible, also under one or more of SysV Unix,
BSD Unix, or Linux, using appropriate vendor or FSF compilers. Beginning with
this release, only two free compilers have been used for testing:
- The free Digital Mars compiler
is a direct descendent of the family of compilers written by Walter Bright.
This family includes the Datalight, Zortech, and Symantec C/C++ compilers.
This compiler was chosen because it's fast, it's free, it's available, and
it's very compatible with both Microsoft C/C++ and the existing language
standards.
- The Free Software Foundation's Gnu
C/C++ (GCC) compiler is the standard compiler for Linux and has become a
de facto standard on many other platforms as well. There are very few
environments where you can't find a port of GCC to run. The SNIPPETS GCC port
of choice for DOS/Win systems is
Mingw32. This is an unusually complete and robust port, even including such
features as full dirent.h support, lacking from other DOS/Win GCC ports.
These compilers work with Unix (all flavors), Linux, DOS, and Win32. Accordingly, I
have discontinued support for OS/2, Amiga, Win16, and other less mainstream OS's.
You will still find some OS/2-specific legacy code in SNIPPETS, but it hasn't been
tested since 1997 and I can't vouch for its usability. I may be able to provide
continued support for Mac, but until such time as I can get a dedicated Mac
compiler (probably Metrowerks CodeWarrior), further Mac support has been suspended.
In the meantime, I suggest that users of these and other unsupported OS's look
around for a port of GCC for their platform.
What does this change mean to the user? The bad news is that it may mean more
work if you're using a compiler which isn't compatible with these two (which in
turn means your compiler isn't compatible with either the standards or with
Microsoft). The good news is that, released from the requirement of much of the
conditional code used to support multiple compilers, SNIPPETS code is once again
easy to read. This is especially true in light of the change in the organization
of the SNIPPETS collection(s) - see "What's new?"
below.
Compiling SNIPPETS code:
SNIPPETS files fall into 4 categories:
- Macros and true code snippets. These will not compile to anything
meaningful by themselves. Macros are designed to be included in file headers,
while code snippets are incomplete pieces of code used to demonstrate a
general principle. Most SNIPPETS macros appear near the beginning of
collections and/or sections archive in .H files. True snippets are rare, but
should be obvious when you run across one.
- Functions. Most of the SNIPPETS files are functions. Many SNIPPETS
functions also have test code built-in which will allow them to be compiled
to stand-alone versions by defining the macro TEST during the compilation
process. Individual functions appear in the archive immediately following the
macros. SNIPPETS also contains larger, multi-file function packages, noted in
each specific section.
- Stand-alone utilities. Many utilities contain useful functions and
demonstrate useful C programming techniques. Most of these have been moved to
the Applications section.
- Educational files. Between the individual functions and the function
packages comprising two or more files, there is a short section of text files
answering frequently-asked questions or providing tutorials on various
aspects of C programming.
What's new in SNIPPETS?
As already noted, the most notable change is that SNIPPETS is now a web-based
archive rather than ftp-based. However, much more fundamental changes have
occurred in its organization. The most obvious of these changes is that the
collection has been split into several separate collections, each targeted at a
specific audience. Beginning with this (September, 2003) release of the web site,
the following collections are supported:
- C code (most C code can be used with C++ compliers)
- Generally portable code for Posix/Linux and Win32
- Code for porting between platforms and/or compilers
- C-specific FAQ and documentation files
- Exclusively C++ code (this section)
- Generally portable code for Posix/Linux and Win32
- C++-specific FAQ and documentation files
- Java code
- Generally portable code for Posix/Linux and Win32
- Java-specific FAQ and documentation files
- Python code
- Generally portable code for Posix/Linux and Win32
- Python-specific FAQ and documentation files
- D code (see the Digital
Mars web site)
- Generally portable code for Posix/Linux and Win32
- D-specific FAQ and documentation files
- Perl code
- Generally portable code for Posix/Linux and Win32
- Perl-specific FAQ and documentation files
- DOS code
- C code
- C++ code
- X86 Assembly code
- DOS-specific FAQ and documentation files
- Embedded systems code
- C code
- EC++ (see the Embedded C++
web site)
- Embedded system-specific FAQ and documentation files
- Applications & information
- Utilities in all supported languages
- FAQ files
- Links
What does this mean for SNIPPETS users? Well first of all, it means that much of
the confusing platform-specific conditional code is no longer there. Secondly, it
means that, rather than the conditional code, the same function may appear in
several specific collections. Finally, and perhaps most obviously, it means that
it will be easier for users to find the things they're really interested in
without having to wade through files which aren't really appropriate for them.
Also, by splitting the collection in this way, it leaves the door open for others
to contribute collections specific to other languages and environments. Stay tuned
for further developments.
The SNIPPETS rationale
Where do SNIPPETS come from?
I'm constantly on the lookout for new SNIPPETS material. The goal of SNIPPETS has
been to collect useful pieces of code that would be free for reuse. This limits
consideration to code that is either explicitly in the public domain or which
carries a free use license with few or no restrictions which would prevent its
use. Current SNIPPETS material has been collected from the C_Echo (a Fidonet
Echomail group, the C_Echo has been gated to Internet mailing lists and may
eventually be gated to the SNIPPETS C mailing list as well), the comp.lang.c
newsgroup, various public domain archives, submissions, and my own commercial
library (MFL, now out of print).
How are SNIPPETS selected?
As the collection has evolved, it's taken on distinguishing characteristics based
largely, I'm afraid, on what sorts of things interest me. A primary focus of
SNIPPETS is portability - first of all between DOS compilers, and
secondly with the larger world of Unix and other platforms. I tend to be interested
in the same problem domain as Posix - system and utility functions. What
I previously have not been interested in trying to include are things which really
require massive amounts of code to do right (e.g. GUIs, databases,
interrupt-driven comm I/O, game-quality graphics, multimedia, etc.) and are
therefore better addressed by large single-purpose packages, whether commercial or
otherwise. However, due to the other changes in SNIPPETS, these will henceforth be
considered as well.
Since I also make my living programming embedded systems, you'll also find a
number of functions useful in an embedded environment. This is also the reason
why there's still so much DOS code in SNIPPETS - DOS is still quite
commonly used on embedded single board computers (SBC's).
In addition to the utility stuff, I also snag anything that seems moderately
obscure (e.g. ISBN validation, wind chill, sunrise/set time, etc.) Whether I need
to know these things or not, someone sometime will need to be able to do these
and I like to be able to provide the option of a simple canned solution rather
than sending them on a research spree.
What makes one SNIPPETS entry "better" than other candidates?
Anything that enhances portability or usability is better in my book. Note that
I'm not necessarily soliciting completion to full library standards. As the name
SNIPPETS implies, many of the entries knowingly have minimal bullet-proofing.
Most of the entries I've excerpted from MFL differ only in that my commercial
code provides bullet-proof error trapping at the cost of slightly obfuscating the
algorithms. In cases where error trapping would, in my opinion, make the
algorithm harder to follow, I've generally opted for clarity over safety. This
was a conscious decision since the target audience for SNIPPETS includes both
newbies and experienced programmers. The pros will recognize the shortcomings and
know to add the error trapping, but the tyros can tend to get lost. My yardstick
on this has been feedback. If too many tyros have to ask how it works, then I try
to simplify and/or make the underlying algorithm stand out. If too many folks
complain about it being unsafe, I add more bullet-proofing. When I hear as little
from both sides as possible, I figure I've achieved the desired balance.
Is the SNIPPETS collection only for PC's?
No. More and more portable code has been introduced into the collection over the
years so that now there is more portable code (although some will require minor
work) than PC-specific code.
Is SNIPPETS only a collection of C code?
No. There have always been a few PC-specific assembly routines in SNIPPETS, and
the current collection includes a growing number of reusable C++ classes. In some
cases, SNIPPETS includes both a C and C++ solution to a particular programming
question. However, as the SNIPPETS archives project broadens, many of these files
will be moved to the new areas.
Legal/copyright information
All the code I put into SNIPPETS for distribution is Public Domain or free
to the best that I can determine. What this means is that:
- I know or can contact the original author(s) to verify the presumed
copyright ownership, and
- The work bears an explicit Public Domain notice, or
- The work is copyrighted but includes a free use license, or
- The work was published without a copyright notice prior to the effective
date of the new copyright law in 1988.
This has been occasionally annoying when I've had to pass up some useful piece of
code because it's questionable whether anyone can use it without incurring
liability (distributing someone else's property makes me an accessory to
infringement).
Since SNIPPETS includes both public domain and free code, be sure to carefully
read each header for any free license restrictions which may apply.
Portions of SNIPPETS are from my own MicroFirm Function Library (MFL). These are
provided for free, subject to the license restrictions specified in the
LICENSE.MFL file. Briefly, it says you can use the source files to create
programs for any use, even commercial distribution, but you can't sell the source
itself or object files (alone or in libraries) built from the source, nor can you
remove the copyright notice.
Sharp-eyed users will note that the pages of this web site each carry a copyright
notice. This simply means that the web pages used to navigate this site as well as
instructional text are copyrighted. The code remains free!
Credits
SNIPPETS special thanks to...
| Auke Reitsma |
Jon Guthrie |
Jerry Coffin |
Ray Gardner |
Dave Burton |
...without whose assistance and
supererogation,
SNIPPETS would not be what it is today!
SNIPPETS Authors:
| Jens M Andreasen |
Scott Andrews |
Erik Bachmann |
Ed Beroset |
| Ed Blackman |
J. Blauth |
Carey Bloodworth |
Walter Bright |
| Gary S. Brown |
Jon Burchmore |
Doug Burger |
Joseph Carnage |
| Joe Celko |
Dave Chapman |
Sreenath Chary |
Andrew Clarke |
| Jerry Coffin |
Fred Cole |
Marty Connely |
Eric Coolman |
| Mark Corgan |
Ross Cottrell |
Carl Declerck |
Mike Demski |
| Brian Dessent |
DECUS |
Michael Dehlwes |
Pieter de Jong |
| Mark Devlin |
Mike Dodd |
Bob Dolan |
Scott Dudley |
| Rob Duff |
Jeff Dunlop |
Paul Edwards |
Jay Elkes |
| David Engel |
David L. Fox |
Jeffery Foy |
Jeff Galbraith |
| Ray Gardner |
David Gersic |
David Gibbs |
gk |
| D. Goodenough |
Jerry Gore |
J-Mag Guthrie |
Jon Guthrie |
| Wayne Halsdorf |
Wayne Hamilton |
Dave Hansen |
David Harmon |
| Blair Haukedal |
K. Heidenstrom |
Dan Hoey |
Maynard Hogg |
| Jerry Houston |
Larry Hudson |
Joe Huffman |
Matthew Hunt |
| Shamim Islam |
Bob Jarvis |
Ted Jensen |
Thor Johnson |
| Paul Johnston |
M. Jones |
Mike Jones |
Mark Kamradt |
| Arjen Kentner |
J. Kercheval |
Mark Kimes |
Wayne King |
| Dave Knapp |
Don Kneller |
Gilles Kohl |
Ed Kowalski |
| Dan Kozak |
Kurt Kuzba |
Jari Laaksonen |
Scott Ladd |
| Soleil Lapierre |
Stephen Lindholm |
Phil Linttell |
Lynn R. Lively |
| John Lots |
Martin Maney |
Robert Mashlan |
Darin McBride |
| Ray L. McVay |
Greg Messer |
Stan Milam |
Peter Miller |
| Robert Morgan |
Craig Morrison |
Keiichi Nakasato |
Lynn Nash |
| Bob Nelson |
Phi Nguyen |
VinhHao Nguyen |
Jeffrey Nonken |
| David Nugent |
Jim Nutt |
S. Offermann |
Heinz Ozwirk |
| Curtis Paris |
Gary A. Parker |
Ruurd Pels |
F. Piette |
| Steve Poole |
Dustin Puryear |
Mike Ratledge |
Auke Reitsma |
| John Rex |
Cliff Rhodes |
Sid Rogers |
L. Satenstein |
| Paul Schlyter |
E. Schneider |
Charles Simonyi |
Ron Sires |
| Branislav Slantchev |
Mike Smith |
Thad Smith |
Robert Sprawls |
| Michael Stapleton |
Mark Stephen |
Bob Stout |
Aare Tali |
| Peter Thomas |
Ratko Tomic |
Tom Torfs |
Nigel Traves |
| Erik VanRiper |
Chad Wallace |
Jim Walsh |
Bruce Wedding |
| Bill Wilkie |
Ross Williams |
Stephan Wilms |
HenkJan Wolthuis |
| Peter Yard |
Yoshi |
Martin Zacho |
Please support SNIPPETS!
Web site pages ©2001-2003 by Bob Stout, all rights reserved
All source code free as noted.