passing arrays by value

ron vaughn rjv at ihdev.UUCP
Fri May 17 01:48:50 AEST 1985


i said earlier:
>quick and simple:  in c i wanted to pass an array by value.  oops.  hmmmm.

i've already received a few letters saying "are you sure you mean by value??"
i should have explained, i was doing the classic "knights tour" problem,
using branch and bound techniques.  classic b&b differs from regular
ol' backtracking, it builds a big tree, and keeps a local version
of the board at EACH node in the tree.  hence each recursive call to
place a knight on the board must pass the board by value.  
on the other hand, with most backtracking you can keep one version of 
the board and work with it only.
these comments on b&b and backtracking algorithms are generalizations.
there are exceptions, b&b can be forced to use pass by reference, but
pass by value is much cleaner. (who cares about memory...)

it is kind of interesting to compare C to, say, pascal, where
you use "var" (or whatever, i hate pascal) to explicitly state you
want pass by reference.  from a user viewpoint, pascal makes sense,
you tell it how you are passing.  in C it looks like everything
is passed by value (so you wind up passing &thing to get pass by reference)
except for arrays, which apparently can't be passed by value.
this *almost* makes sense...

does this really matter?  am i still missing something??  is there
a reason arrays are special -- the "array IS a pointer" argument, perhaps??
is the array==pointer at the heart of C and thinking anything else
a valid reason for public flogging???

	keep those cards and letters coming,

	ron vaughn	...!ihnp4!ihdev!rjv

More information about the Comp.lang.c mailing list