Newsgroups: comp.theory,comp.lang.scheme,comp.software-eng,comp.lang.c
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!news.nic.surfnet.nl!sun4nl!cwi.nl!dik
From: dik@cwi.nl (Dik T. Winter)
Subject: Re: Compiler capabilities, and C semantics (was: Style: multiple returns and relatives)
Message-ID: <DIIyG0.C2@cwi.nl>
Sender: news@cwi.nl (The Daily Dross)
Nntp-Posting-Host: chrysant.cwi.nl
Organization: CWI, Amsterdam
References: <48nni8$klj@ixnews4.ix.netcom.com> <48q9f4$2sj@camelot.ccs.neu.edu> <492je7$24m@Starbase.NeoSoft.COM>
Date: Fri, 24 Nov 1995 01:50:24 GMT
Lines: 43
Xref: glinda.oz.cs.cmu.edu comp.theory:14682 comp.lang.scheme:14384 comp.software-eng:39260 comp.lang.c:164634

In article <492je7$24m@Starbase.NeoSoft.COM> claird@Starbase.NeoSoft.COM (Cameron Laird) writes:
 > >    int f (int x[]) {
 > >        int t1 = x[0];
 > >        h(t1);
 > >        return t1 + x[0];
 > >    }
...
 > >    int g (int x[]) {
 > >        int t1 = x[0];
 > >        h(t1);
 > >        return t1 + t1;
 > >    }
 > 			.
 > No.  This is a bit embarrassing, and I've been waiting
 > for someone else to explain it, but none of the numer-
 > ous follow-ups have done so.  C passes arguments by
 > value.  h() can't affect x[0] (with the exception of
 > horrible memory manipulation, which I can argue is not
 > under consideration here).

Eh?

int x[10];
void h(int y) {x[0] = y + 1;}
main() { x[0]=0; printf("%d\n", f(x)); x[0]=0; printf("%d\n", g(x)); }

C passes by value, but the definitions of f() and g() are misleading.
Actually better would be a header like "int f (int *x)" etc. (which
is identical due to the rewrite rules).  C never passes arrays, not
by value and not by reference.

 > In fact, FORTRAN looks more like a problem child in this
 > situation, because its subroutine's side-effects can bub-
 > ble back up as you have in mind.

Show me such a program and I will show you were it violates the standard.

 > I've moved follow-ups around.

And I moved the thread back again.
-- 
dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland, +31205924098
home: bovenover 215, 1025 jn  amsterdam, nederland; http://www.cwi.nl/~dik/
