2d arrays in C

Richard O'Keefe ok at mudla.cs.mu.OZ.AU
Mon May 28 17:10:39 AEST 1990


We've had a lot of fun arguing about what dynamic arrays in C _should_
look like and whether it's doable.  To be really helpful and productive,
I thought I'd share a README file with you.  (One fine point:  the data
structure used here for 2d arrays would **NOT** work with fwrite.)
This came out in 1988, I think to comp.sources.misc.  I believe that the
author of the package has since moved.

	/* README for xxalloc */

xxalloc is a family of routines for dynamic array manipulation in one,
two and three dimensions.  Routines are included for allocation,
initialization, printing, renumbering, and freeing both arrays of
structures and arrays of simple types.  Since the "edge-vector" approach
is used for two and three dimensional arrays, this set of routines
allows for the development of reusable subroutine libraries without
regard to some "maximum" dimension.  Both positive and negative indices
are allowed. 

When I converted to C several years ago after my first large program in
FORTRAN, the first thing I wanted to do was to have adjustable
multi-dimensional arrays.  This can be achieved in C (sort of, the array
dimensions are fixed) through the use of pointers (the so called
"edge-vector" approach, see also K&R p.  110).  I then added routines
for manipulating structures and routines for renumbering the indices,
initializing, and printing.  These routines also solve the problem of
not being able to have 2D arrays greater than 64k on machines with 16
bit addresses (ie.  PC's). 

Installation instructions are in the makefile.  A test program is
included to exercise most of the package.  I have compiled this package
on many machines (SYS5, BSD, MSDOS) without a hitch.  The man page uses
some abbreviation to save space since there are actually 109 functions
in this package. 

--
Harold G. Walters                 Internet: walters at ce.okstate.edu
School of Civil Engineering       Uucp: {cbosgd, ihnp4, uiucdcs}
Oklahoma State University               	!okstate!osubem!walters
Stillwater, OK 74078 "If all you have is a hammer, everything looks like a nail"



More information about the Comp.lang.c mailing list