The SNIPPETS Archives Project
Tuesday, 09-Feb-2010, 05:35:46 GMT
Last modified: 31-Mar-2007, 04:10:23 GMT
218083 visitors since 14-Sep-2003
A minimum screen size of 600 x 800 is recommended for viewing SNIPPETS
Archivist: Bob Stout
"The parable of the two programmers"
Every programmer should read this!
What is SNIPPETS?
The SNIPPETS archives project started out in the late 1980's as a personal quest 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 was
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 and outgrows it C/C++ roots. Although the
centerpiece of the SNIPPETS project will continue to be its archives of free source
code and applications, it now will encompass Java, D, Python, Perl, Embedded C/C++,
and DOS C and assembly for embedded systems work. At first, only the C, C++,
Embedded, DOS, and applications/links areas will be populated, however there is a
plan to grow these.
This leads to next key piece of the new SNIPPETS world - the conferences. Read more
about them below.
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, Java script, 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.
Portability:
One major change in this release is in the testing philosophy. In the past,
all SNIPPETS C/C++ 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 generally portable code will be published, tested with the more
popular (i.e. typically low-cost or free) compilers. For my part, as a minimum, I
test with the Digital Mars (nee Zortech,
nee Symantec) compiler and the MinGW32 compiler
using the MSYS shell (also found at the MinGW32 web site). I also sometimes test
using gcc under either Debian or
Kubuntu Linux. The reason for choosing these
is quite simple - the Digital Mars compiler is free for non-commercial use and is
extremely compatible with Microsoft's C++ compiler which is the most popular
compiler in the Windows PC world, and gcc in its various incarnations is the most
popular compiler everywhere else. MinGW32 is an excellent Windows port of gcc while
compiles native Win32 applications. I test on Debian and Ubuntu because those are
the other systems I have. Further adaptation to specific development environments
and tool sets will be left to the user, although some conditional code for other
compilers remains in some source files.
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 section archives. True snippets are rare, but should be
obvious when you run across one.
- Functions/objects. Most of the SNIPPETS files are functions or objects.
Many SNIPPETS functions/objects also have test code built-in which will allow
them to be compiled to stand-alone versions during the compilation process.
SNIPPETS also contains larger, multi-file function packages, noted in
each specific section.
- Stand-alone utilities. Many utilities contain useful functions and
demonstrate useful programming techniques. Most of these have been moved to
the Applications section.
- Educational files. There exists a short section of text files answering
frequently-asked questions or providing tutorials on various aspects of
programming. Many of these have been moved to the
Applications section.
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. Legacy SNIPPETS material was collected primarily 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). As noted, future additions to the other language
archives will come from users and subscribers supporting SNIPPETS.
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 PC compilers, and secondly
with the larger world of Linux 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.
Not surprisingly, I apply the same standards to code donated for publication. Given
a choice of more than one code set which perform more or less the same task, I'll
rank them on portability, readability, and the clarity and robustness of their
design.
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. With the addition of support for other languages, much
of the emphasis will shift away from PC-specific code.
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!
Conferences
One key component of the new SNIPPETS world is the conferences. For each of the
specific topic areas, there will exist a lightly moderated Internet mailing list
conference devoted to its discussion. By encouraging discussion and the free
exchange of ideas and designs, we hope that the code archives will fill up quickly
in each area. The specific areas and their topics are:
- C code
- Generally portable code for Posix/Linux and Win32
- Code for porting between platforms and/or compilers
- C-specific FAQ and documentation files
- C++ code
- Generally portable code for Posix/Linux and Win32
- C++-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
Credits
SNIPPETS authors are credited in the individual sections, however 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! Extra special thanks go to Auke Reitsma.
Auke passed away in April, 2003, and the SNIPPETS C site is dedicated to his memory.
Please support SNIPPETS!
©2001-2007 by Bob Stout, all rights reserved
All source code free as noted.
| Tested with: |
lynx 2.8.5
|
| Support: |
|