It's exactly this way,
&record is the address of the structure named record,
and the address is passed "by value", that is,
copied to the stack.

When teaching C language, I always say, that all arguments are passed "by value", even x (if x is a vector) is passed "by value" because x is the same as &x[0],
which is the address of the first element of x.

there are more such equivalences:

*x is the same as x[0]
*(x+1) is the same as x[1]

and even if you have a pointer p instead of a vector x, for example

p = &x[5];

or

p = x + 5;

(which is the same)

you can then use the expressions

*p
p[0]
*(p+1)
p[1]

which refer to the element x[5] and x[6], respectively.

This is completely independent of the base type of x and p,
it could be char, int, long, double or a structure type.

By the way: the term "by value" is inherited from ALGOL; there are
two parameter passing mechanisms in ALGOL - by value and by name -
no by reference. By name is similar to by reference, but more complicated -
and not the same.

I would say that "by value" tries to give a "logical" description of the
parameter passing mechanism, where "copy to the stack" is a
technical implementation of the parameter passing mechanism -
there could be other ones. Same goes for "by reference" and
"by name".

It is interesting to compare the languages on their parameter passing
mechanisms:

ALGOL: by value - by name
FORTRAN: by reference
PL/1: by reference - dummy arguments by reference (with paranthese) - only recently by value
PASCAL: by value - by reference
C: always by value - by reference only by explicitly passing pointers

Kind regards

Bernd




Am 01.07.2013 01:15, schrieb Steve Comstock:
On 6/30/2013 3:58 PM, Bernd Oppolzer wrote:
As I pointed out earlier, C NEVER passes arguments by reference.

Well, if you pass, say &record then the address of record
is passed in the argument list, so record is passed by
reference. However, one could argue that '&record' is a
pointer and the pointer is being passed by value so that
the data is being passed by reference.

Angels and pin heads, eh?


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

Reply via email to