Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rphroy!caen!sdd.hp.com!apollo!vinoski From: vinoski@apollo.HP.COM (Stephen Vinoski) Newsgroups: comp.sys.apollo Subject: Re: function prototype mystery? Message-ID: <5102cefd.20b6d@apollo.HP.COM> Date: 16 Apr 91 17:28:00 GMT References: <1991Apr11.164655.17092@milton.u.washington.edu> Sender: root@apollo.HP.COM Reply-To: vinoski@apollo.HP.COM (Stephen Vinoski) Organization: Hewlett-Packard Apollo Division - Chelmsford, MA Lines: 67 In article <1991Apr11.164655.17092@milton.u.washington.edu> etb@milton.u.washington.edu (Eric Bushnell) writes: >I'm using the apollo system call proc2_$get_info(), >which is defined in proc2.h as: > >void proc2_$get_info( > uid_$t &p2_uid, > proc2_$info_t *info, > pinteger &info_buf_len, /* size of info buffer (bytes) */ > status_$t *sts >); > >What do the &'s do to the first and third arguments? That indicates that the arguments are to be passed by reference. This is a Domain/C extension borrowed from C++. Domain/Pascal passes arguments by reference by default, and this extension allows C and Pascal to interface very easily, much easier than with the std_$call() stuff from the pre-sr10 days. >It looks to me like the function expects addresses, but if >I pass addresses to it, the compiler (cc 6.7.m, OS10.3) complains >that the argument type conflicts with the declaration. You don't need to pass addresses. The compiler will take care of everything for you. For instance, given this function: void incr(int &x) { x++; } This function can be called like so: int j = 5; incr(j); The variable j will now contain the value 6. This can be done with pointers: void incr(int *x) { (*x)++; } but this version of incr() must be called like this: int j = 5; incr(&j); Note, however, that unlike C++, Domain/C will not generate a temporary in the case where a constant is passed by reference, so the following will cause an access violation: incr(5); A constant can safely be passed by reference if the function does not modify its argument. All of this is covered in section 5.3.2 of the Domain C Language Reference (002093-A00) (that's where this example came from). -steve | Steve Vinoski (508)256-0176 x5904 | Internet: vinoski@apollo.hp.com | | HP Apollo Division, Chelmsford, MA 01824 | UUCP: ...!apollo!vinoski | | "The price of knowledge is learning how little of it you yourself harbor." | | - Tom Christiansen |