Implementation of alloca() and friends

Brandon S. Allbery allbery at ncoast.UUCP
Sat Jun 18 09:39:32 AEST 1988


As quoted from <16072 at brl-adm.ARPA> by enag at ifi.uio.no on dynamic arrays:
+---------------
| Doesn't this look very clumsy to do in such a neat language as C?
| Having to remember dimensions and their individual sizes (even opening
| up for bounds checking - shock horror! :-), and building nasty access
| poly(g)nomes requiring lots of CPU time even for tiny little two-
| dimensional matrices...  It sounds Wrong to me.  Also, the bugs that
| will appear because people forget to pass along the dimensions of their
| conformant arrays -- leading all the way to sending a pointer to an
| array descriptor structure, slowing down all the code we're so proud
| of.
+---------------

Why not allocate matrix[n][m] by allocating an array[n], then set each element
to a pointer to an array[m]?  This makes the [] operator work exactly the way
it does everywhere else:  x[n] == *(x + n) without having to do hairy
calculations to access an element of an n-dimensional matrix.  No more likely
to have bounds checking than any other part of C.  ;-)

++Brandon
-- 
Brandon S. Allbery			  | "Given its constituency, the only
uunet!marque,sun!mandrill}!ncoast!allbery | thing I expect to be "open" about
Delphi: ALLBERY	       MCI Mail: BALLBERY | [the Open Software Foundation] is
comp.sources.misc: ncoast!sources-misc    | its mouth."  --John Gilmore



More information about the Comp.unix.wizards mailing list