[TUHS] C declarations.

Stephen Kitt steve at sk2.org
Sun May 14 01:36:48 AEST 2017

On Sat, 13 May 2017 12:42:47 +0000, Michael Kjörling <michael at kjorling.se>
> On 13 May 2017 13:35 +0100, from tfb at tfeb.org (Tim Bradshaw):
> > Are there languages that copy arrays in function calls defaultly?
> > Perhaps Fortran has some convention that allows that but I doubt it
> > gets used very much, because it would be insane in most cases:
> > COMPUTE_MEAN_TEMPERATURE(ATMOS) is really *not* going to work very
> > well if it involves copying the ATMOS array.  
> I'm not completely sure about arrays, but at least Java has pass by
> reference in some cases where you might expect pass by value. IIRC
> function return values is a prime example.

Technically (and this is serious nit-picking), Java is always pass-by-value,
but the value of an array or object *variable* is the reference to the array
or object, not the array or object itself. So the behaviour is
pass-by-reference for arrays and objects (although that’s a simplification
too, and unhelpful in some instances).

The same applies to return values: primitive types are returned by value
(copied), arrays and objects are returned via their reference (which is
copied too).



More information about the TUHS mailing list