Call by [Value, Reference] V1.1

Sean Malloy scm3775 at tamsun.tamu.edu
Thu Mar 28 13:44:13 AEST 1991


I just posted (most of) this article.  Then I realized that I didn't
clarify my position well enough.  Welcome to V1.1.


Sorry to waste bandwidth with such a trivial question, but it will
settle an argument, and it *is* about C.

Given the following fragment:

char arrb[] = "mine";   /* not global */
fcn_c( arrb );

-------

int fcn_c (char arrb [])
{
   arrb[3] = 't';
}


Is the above an example of call by value or call by reference?

My friend insists that it is a call by value, since fcn_c gets a
*copy* of the pointer arrb.  However, he believes that C *can*
make calls by reference.  If he's to have that belief, doesn't
it look like this is one of the occasions that *must* be a
'call by reference'? (Yes, I know that K&R says that all calls
are by value.  What I'm saying here is: ASSUME that C can have
calls by reference.  Wouldn't the example above be an example of
CBR?)

The proof he uses to show that the above is CBV is that 
fcn_c gets a copy of the pointer 'arrb', thus
satisfying the definition of CBV.  (essentially correct).
But you can extend his argument to all calls that appear to be CBR
and prove them to satisfy the parameters for being a CBV.

Yet he maintains that C can do CBR, and he rejects my allegation
that saying that CBR's exist in C, and *not* calling the above
a CBR is inconsistant.  (I'm trying to show him that his
argument can be used on any 'CBR' to show that it is a CBV).

Suggestions/insight?

-Sean

/*--------------------------------------------------------------------------*\
| Sean C. Malloy  = ("x041sc at tamuts.tamu.edu" || "scm3775 at tamsun.tamu.edu")  |
\*--------------------------------------------------------------------------*/
              You'll pay to know what you REALLY think.

/*--------------------------------------------------------------------------*\
| Sean C. Malloy  = ("x041sc at tamuts.tamu.edu" || "scm3775 at tamsun.tamu.edu")  |
\*--------------------------------------------------------------------------*/
              You'll pay to know what you REALLY think.



More information about the Comp.lang.c mailing list