From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,60dd4fe7723c0ef X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Ada Core Technologies announces GNATCOM Date: 2000/04/12 Message-ID: <8d2d8j$1tk$1@nnrp1.deja.com>#1/1 X-Deja-AN: 610285179 References: <8coc5e$do2$1@nnrp1.deja.com> <8d0ru2$arc$1@nnrp1.deja.com> <8d1paa$n0n4@ftp.kvaerner.com> X-Http-Proxy: 1.0 x39.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed Apr 12 17:54:36 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-04-12T00:00:00+00:00 List-Id: In article , "David Botton" wrote: > Turbo C did that and many compilers still do. > > David Botton Since I see David sharing the confusion, perhaps an example is appropriate int clobber (struct q m) { m.a++; return m.a; } called in c passing a value of the struct type does NOT change the value of the passed variable. But the RM requires (well its AI, but in practice we have treated it as a requirement for the purposes of interoperability) the corresponding Ada function function clobber (m : q) return int; to be interfaced by using call by reference, as a result of which clobber will destroy the passed parameter. But you can't unconditionally create a copy, since you may want the reference semantics. Indeed the thought behind the bad advice in the RM is that usually the C function will look like int clobber (struct q *m) .... in which case the call by reference is appropriate. The effect of C_Pass_By_Copy is to force the appropriate C calling sequence for a pass by value, i.e. assuming that the value is reasonably large, create a copy on the calling side, and then pass a pointer to the copy. I hope that makes this clear, I am surprised how many people seem incredibly confused on this issue. Part of the trouble historically is that C did not allow structs to be passed by value till later on, so it is not typical C style to use this feature. This means that indeed the most common convention for passing records in C is to pass them by pointer, but although this is indeed the most common case, it was a goof in the RM to leave Ada programs with no way of passing records by value. Remember, call-by-address and passing-in-registers are implementation techniques. call-by-reference and call-by-value are high level semantic concepts. Don't get the two confused. Sent via Deja.com http://www.deja.com/ Before you buy.