If you pass a scalar variable as an argument to a function and in that
function you change the value of the corresponding parameter, the value of
the original variable is not affected.  This is pass by value.

If you pass an array as an argument to a function and in that function you
change the value of some corresponding parameter array elements, the
original array is modified.  This is almost pass by reference.  (In a true
pass by reference, the receiving function would be able to determine the
dimensions of the array.)

If you pass a structure variable as an argument to a function and in that
function you change the value of some corresponding parameter members, the
value of the original structure members is not affected.  This again is PASS
BY VALUE.

The same applies to a union argument.

The only aggregate that is not passed by value is an array.

To avoid the overhead associated with large structures, most C functions
expect pointers to (possibly const) struct.

:>: -----Original Message-----
:>: From: IBM Mainframe Discussion List [mailto:[email protected]] On
:>: Behalf Of John Gilmore
:>: Sent: Sunday, June 30, 2013 11:28 AM
:>: To: [email protected]
:>: Subject: Re: Theology question: Parameter formats
:>:
:>: Steve Comstock wrote:
:>:
:>: <begin extract>
:>: My whole point was to address the assertion from an earlier point in
:>: this thread that C invariably passes arguments by reference.
:>: </end extract>
:>:
:>: and it is well that he did so.
:>:
:>: C has historically passed scalars by value, a silly term that means by
:>: copying their current values on to the stack.  As many people here
:>: know, I am no great admirer of C; but it is not a silly language.  It
:>: never passed aggregates, chiefly arrays and structures, "by value".
:>:
:>: John Gilmore, Ashland, MA 01721 - USA
:>:
:>: ----------------------------------------------------------------------
:>: For IBM-MAIN subscribe / signoff / archive access instructions,
:>: send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to