Lähettäjä: Edward Bartolo Päiväys: Vastaanottaja: dng Aihe: [DNG] Fwd: Studying C as told. (For help)
Hi KatolaZ,
This reply was intended to you, but I mistakenly addressed it to Irrwahn. Sorry.
Edward
---------- Forwarded message ----------
From: Irrwahn <irrwahn@???>
Date: Wed, 22 Jun 2016 19:27:01 +0200
Subject: Re: [DNG] Studying C as told. (For help)
To: Edward Bartolo <edbarx@???>, irrwahn35@???
Cc: dng@???
On Wed, 22 Jun 2016 17:04:38 +0200, Edward Bartolo wrote: > Hi,
>
> Irrwhan35 wrote:
> <<
> There is no "passing by reference" in C. Forget it. No
> references. Only *values*. Everything is passed *by* *value* in C. You
> will never pass "an array" to a function call in C. You will instead
> pass the *value* of a *pointer* to a contiguous region of RAM which
> contains the elements of your array. You pass *an adress*, namely the
> address of the first position in RAM where your array stays, not "the
> array", or a reference to the array. And this is implemented by
> copying on the stack the *value* of the pointer (i.e., the address),
> so that your function can access the array that start at that address.
>>>
Whoa, hold on, that wasn't me! It was KatolaZ.
(BTW: That's "Irrwahn", not "Irrwhan". :^)
> I think, we both are saying the same things, but using different words
> that may have slightly different meanings for us.
That's beside the point. Both terms have very well defined and
very distinct meanings. Hint: E.g. C++ provides the same calling
mechanism, namely call-by-value, as does C, but beyond that also
offers *actual* call-by-reference. It is *very* important to keep
those two apart!
[...] > Therefore, a function's actual parameter declared by a
> program language has to be translated into an address at some point
> before execution.
Not necessarily so. In case of call-by-value the actual
argument that is passed for a formal parameter can very well
be (and often is) the result of an intermediate operation
that has been kept in a CPU register. (Well, the same could
be true for the result of an address calculation, but it's
already getting hairy.)
Not that any of this matters at all: Call-by-value (even if
that value happens to be the explicit address of some object
in memory) is inherently different from call-by-reference.
Full stop.
[...] > This is why I am finding it hard to logically accept that "passing by
> reference" is NOT equivalent to passing a pointer for the machine. For
> the programmer, it is using a different syntax, but the machine sees
> no difference. And since, in the end what programmers do with their
> code is running it on a machine, what a machine sees is what counts,
> at least for me.
Well, for the machine basically /every/ object, even an ordinary
variable whose value is stored in RAM, is just an address. It's
the distinct instructions that use this address in different ways,
e.g. to manipulate the very address itself, or to use that address
to access or alter the value stored at that position in memory.
Yet still, you'd never call an ordinary variable a pointer, or
would you? Although, at the bottom of things, that is what it
really is!
This is one of the instances where you definitely should *not*
attempt to take the POV of the machine to make sense of stuff.
At least if you want to avoid confusion and misunderstandings in
communication with fellow programmers you should definitely stick
to the terms agreed upon decades ago. And sooner or later those
terms will make so much more sense to you that you'll never even
remember the times you had difficulties in telling the concepts
apart.
>
> Edward
Editorial note:
Edward, would it be asking to much to please put your comments
in a reply to the _actual_ message you are referring to? Besides
making your messages easier accessible by not forcing your readers
into having to reconstruct the context, it would also help to
avoid accidental false attribution of quotes, as it has happened
above.
You can earn additional bonus points for snipping the parts of
the quoted material that are not germane to your reply.