DragonFly BSD
DragonFly kernel List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: learning dragonfly or C...


From: "Devon H. O'Dell" <dodell@xxxxxxxxxxxxxxx>
Date: Thu, 11 Nov 2004 10:22:09 +0100

Magnus Eriksson wrote:
On Thu, 11 Nov 2004, Devon H. O'Dell wrote:


The statement:

vpp = &vp

is ``dereferencing'' vp. Dereferencing effectively provides the address
in memory of a variable.



modfunction(int *bar)
{

	*bar = 3; /* Change bar to 3 */
	printf("%d\n", *bar);
	return;
}


modfunction(&foo);



This time, we ``dereferenced'' our variable foo (and, on a sidenote, I
don't know why it's called dereferencing, I think it's a horrible name
and substitute it mentally with ``grab the address of'' whenever I see



It's called dereferencing because a pointer is a reference to something, and dereferencing is the act of doing away with the reference (de-referencing) and handling what is actually pointed to instead. So the opposite of what you said really. Did you get enough sleep tonight? :-)

Oh, right. I did get enough sleep tonight, but I haven't had my cup of coffee yet, so that must be it ;).


 (but *bar = 3 in modfunction() is dereferencing bar though, if that's
what you meant.)

Nope, I really just missed the coffee :\.


  I have no idea what the opposite operation (&) is called.  Referencing?
Nah..


Magnus

Yeah, prefixing with an & is creating a reference; I suppose that _is_ what that's called. Which is why I (correctly) specified somewhere else that we were passing it by reference.


Oh well. The rest of the example is correct. (This is why people get confused with C. Nobody explains pointers right the first time.)

--Devon



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]