Small C?

Rob Warnock rpw3 at redwood.UUCP
Wed Apr 3 10:29:00 AEST 1985

| from: G.V.  Goebel / Hewlett-Packard, Corvallis OR
| I have heard rumors about a "free" "C" compiler called "small C", written
| by a fellow named Ron Cain.  
| Does anybody know much about this?  Does it run on UNIX systems?  Where 
| would I find it?

See the book "The Small-C Handbook", by James E. Hendrix,
Reston Publishing (1984), ISBN 0-8359-7012-4, paperback (256pp).

>From the Introduction:

	     "In May of 1980, Dr. Dobb's Journal ran an article entitled,
	<<A Small C Compiler for the 8080's>>. In the article, Ron Cain
	presented a small compiler for a subset of the C language. The
	most interesting feature, besides its small size, was [it was
	written in Small-C]...
	     "Ron Cain published a complete listing of the compiler and
	graciously placed it in the public domain. Both the compiler
	and the language came to be known as Small-C...
	     "Recognizing the need for improvements, Ron encouraged me
	to produce a second version, and in December of 1982 it appeared
	in Dr. Dobbs Journal... [list of various improvements]... This book
	describes an updated version (2.1) of that compiler and its language."

On the copyright page (or whatever that page is properly called), there is
an address for Hendrix that you can send $25 to get the sources and binaries
for Small-C, on "standard 8-inch SSSD CP/M diskettes". It uses Microsoft's
MACRO-80 assembler. (Or I suppose you could type it in from the book, since
it's all there, but it's 78 pages of ~50 lines each, including the runtimes.)

NOTA BENE: Although the language accepted by Small-C 2.1 has been upgraded
to be much closer to "full" C (specifically in terms of control structures,
various operators, and preprocessing -- "#include", "#define", #ifdef", etc.),
Small-C is VERY 8080-specific! It generates 8080 assembler (including the
"#asm" construct), and the runtime library routines (for 16-bit arithmetic,
multiply, etc.) are written in 8080 assembler.

Remember, Small-C is still a "small" C:

	- The only data types are "char" and "int" (no long/short/unsigned)
	- Arrays may have only one dimension
	- No "struct" or "union" (!)
	- No casts (non needed)

On the plus side, most of the minor source syntax irritations found
in the first version have been fixed (other than the really major ones
listed above).  An appendix, "Compatibility with Full C", is only 2.5
pages, mostly small nits.  While some of them impair compatibilty with
certain questionable constructs in "normal" C (e.g., Small-C does NOT
accept "8" and "9" in octal constants), I saw nothing major if you are
writing in "clean" C. With a small amount of attention to the items
mentioned there, you can write Small-C code that is completely portable
to full C compilers.

All in all, a nice small ad-hoc compiler (as opposed to one using "yacc"
or other compiler generators) for a very restricted environment. Worth
studying if you need a TINY compiler for some other (equally restricted)
environment.  I see no problem with your compiling it and running it
*on* a Unix system (say, in doing cross-development), since the Small-C
compiler itself should be compilable by most Unix C compilers.

However, it certainly cannot handle the constructs commonly used in
*writing* a Unix-like system. For example, it would not be able to
compile Doug Comer's "Xinu" code (which makes heavy use of structs).
The lack of structs and unions is a serious limitation, given modern
systems programming style.

Should you need a compiler for a machine that does not normally have
one, and you are going to be running the compiler on a Unix system
that has "yacc", you might want to look at the "yacc" grammar for
ANSI C that was posted to the net a while back. (Check your local or
neighborhood archives before broadcasting a request for it. I seem
to recall a couple of "bug fix" followups as well.)

Rob Warnock
Systems Architecture Consultant

UUCP:	{ihnp4,ucbvax!dual}!fortune!redwood!rpw3
DDD:	(415)572-2607
USPS:	510 Trinidad Lane, Foster City, CA  94404

More information about the Comp.lang.c mailing list