From mboxrd@z Thu Jan 1 00:00:00 1970 From: steve@sk2.org (Stephen Kitt) Date: Sat, 13 May 2017 17:36:48 +0200 Subject: [TUHS] C declarations. In-Reply-To: <20170513124247.GG9980@yeono.kjorling.se> References: <015401d2caa0$79762650$6c6272f0$@ronnatalie.com> <68E8DC0A-D1B8-4FF0-AD26-ACDC57E308AF@pobox.com> <20170511223232.GM4341@mcvoy.com> <015b01d2caa7$c658c020$530a4060$@ronnatalie.com> <20170513012415.GZ4341@mcvoy.com> <025701d2cb92$ec8182a0$c58487e0$@ronnatalie.com> <20170513122050.GF9980@yeono.kjorling.se> <0CF82AC1-E835-4C06-813F-D9EFD2C12290@tfeb.org> <20170513124247.GG9980@yeono.kjorling.se> Message-ID: <20170513173648.2900e4cd@heffalump.sk2.org> On Sat, 13 May 2017 12:42:47 +0000, Michael Kjörling wrote: > 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). Regards, Stephen