Re: static aray question?
Robby <Robby@discussions.microsoft.com> wrote:
===================
Q#1)
Since the ULC_PASSC_config_passcode() function receives the PASSCODE
obj_PASSCODE pointer by reference
No it doesn't. What makes you think so?
(I guess its by reference and not
by value right?)
Wrong
===============================
Okay, so then we all agree that I was passing it by value .....RIGHT??
This depends on what you mean by "it" here. You were passing PASSCODE*
pointer by value, which also means you were passing PASSCODE object
itself by reference (in the sense the word "reference" is colloquially
used when discussing C programs, where it is pretty much synonymous with
"pointer").
AND
When we pass something by value, its been said over and over again,
that the object or variable is copied into the function, and that any
changes to this variable or object's data will not reflect or be
visible in main or the calling function... RIGHT?
Right. But remember - you were passing a pointer by value, which means
you couldn't change the pointer to point to something else (or set it to
NULL). But you were passing a pointed-to object by reference, meaning
you _could_ change said object through the pointer.
AND
In my previous topic posts, I was told on several occasions that when
we want to pass something by reference, C absolutely requires the "&"
(address of) in front of the variable or object that is being passed
into a function
Consider two equivalent sequences:
void f(PASSCODE*);
PASSCODE pass;
f(&pass); // pass is passed by reference
PASSCODE* p = &pass;
f(p); // pass is still passed by reference. p is passed by value.
It doesn't matter whether you take an address right when calling the
function, or some time before that (and store it in a variable).
Here's an example of passing by reference that doesn't involve an
ampersand:
PASSCODE* p = malloc(sizeof(PASSCODE));
f(p);
free(p);
Here, too, p is passed by value, but the (unnamed) PASSCODE object it
points to is passed by reference.
But in your example you don't put an "&" in front of pPass and you
claim that the data modified in the function will be visible in main
or the calling function?
Changes to pPass are not visible to the caller. Changes to (*pPass) are.
Is it because since pPass is a pointer and when we pass it, it is
automatically understood that its contents is the address >>>>
replacing the need for the "&" ????
Yes, it's understood that a pointer (in most implementations) constains
an address. I don't see where "replacing the need for &" part comes
from - it doesn't make any sense to me.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925