harrismh777 <[email protected]> wrote:
>
>If I call a function in C, and pass-by-value, the data's 'value' is
>placed on the stack in a stack-frame, as a 'value' parm... its a copy of
>the actual data in memory.
>
>If I call a function in C, and pass-by-reference, the data's 'address'
>is placed on the stack in a stack-frame, as a 'reference' parm... no
>data is copied and the function must de-reference the pointer to get to
>the data.... this is by definition.
This is not correct. Consider an example.
int BumpMe( int * a )
{
return *a+3;
}
int Other()
{
int x = 9;
return BumpMe( &x );
}
That is not an instance of passing an "int" by reference. That is an
instance of passing an "int *" by value. The fact that the parameter "a"
in BumpMe happens to be an address is completely irrelevent to the
definition of the parameter passing mechanism.
C has pass-by-value, exclusively. End of story.
>There may be some language somewhere that does pass-by-reference which
>is not implemented under the hood as pointers, but I can't think of
>any...
Fortran had genuine pass-by-reference. In Fortran, you could write a
program like this:
SUBROUTINE CONFUSION(IVALUE)
INTEGER IVALUE
IVALUE = IVALUE + 1
END
PROGRAM MAIN
CONFUSION(4)
END
That program would actually modify the value of the constant 4. Such an
abomination is simply not possible in C. Is that implemented
under-the-hood with pointers/addresses? Of course it is. However, that
does not change the parameter passing model as defined by the language
specification.
--
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list