Re: Another spinoza challenge
- From: "Chris M. Thomasson" <no@xxxxxxxxxxxx>
- Date: Tue, 25 Aug 2009 10:36:08 -0700
"spinoza1111" <spinoza1111@xxxxxxxxx> wrote in message news:39ea5c77-5a58-443f-a103-a3101c46253c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Aug 25, 1:09 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
Phil Carmody said:
> Kenneth Brody <kenbr...@xxxxxxxxxxx> writes:
<snip>
>> It appears that some people can't grasp the fact that passing a
>> variable by reference, and passing the address of a variable by
>> value
>> are not the same thing. (Yes, you can achieve the effect of
>> changing the caller's variable's value by doing pointer-by-value,
>> but that doesn't make them the same thing.)
> It appears that some people can't grasp the fact that one can
> effect pass by reference by passing variables by address.
Only by torturing the concept of pass by reference beyond its yield
point. If passing the address of a variable were equivalent to
passing by reference, then the following program would print 42:
#include <stdio.h>
void byref(int *p)
{
p = 42; /* bug - p was *not* passed by reference. */
}
This might be a better "representation" of references:
______________________________________________________
#define ref *
#define toref &
void inc(int ref self)
{
int ref r1 = self;
int prev = ref r1;
ref self = 5;
assert(ref r1 == 5);
ref r1 = 6;
assert(ref self == 6);
ref self = prev + 1;
}
void foo()
{
int v = 0;
inc(toref v);
assert(v == 1);
}
______________________________________________________
lol.
.
- References:
- Another spinoza challenge
- From: spinoza1111
- Re: Another spinoza challenge
- From: Richard Heathfield
- Re: Another spinoza challenge
- From: spinoza1111
- Re: Another spinoza challenge
- From: Richard Heathfield
- Re: Another spinoza challenge
- From: Kenneth Brody
- Re: Another spinoza challenge
- From: Phil Carmody
- Re: Another spinoza challenge
- From: Richard Heathfield
- Re: Another spinoza challenge
- From: spinoza1111
- Another spinoza challenge
- Prev by Date: Re: Another spinoza challenge
- Next by Date: Re: A C showstopper
- Previous by thread: Re: Another spinoza challenge
- Next by thread: Re: Another spinoza challenge
- Index(es):
Relevant Pages
|