[Nickle] references in structured values
keithp at keithp.com
Thu May 20 23:05:12 PDT 2004
Around 1 o'clock on May 16, Bart Massey wrote:
> I'm having some issues with references in structured values
> (arrays and structs). I guess x.m is implicitly
> dereferenced at some point before its address is taken.
> This seems bad: you sometimes want to initialize these things
> by passing their address. Am I confused?
Yes, you have been confused by ref typed variables. But, there's also a
Remember that a ref type (&int) is semantically equivalent to a pointer
type (*int); the only difference is that the compiler 'sugars' all
variables of that type:
int i; int i;
int j; int j;
&int r; *int p;
*&int pr; **int pp;
&r = &i; p = &i;
r = 12; *p = 12;
pr = & &r; pp = &p;
*pr = &j; *pp = &j;
Except that 'pr = & & r;' doesn't work. That's because the type of '&r'
is &int, and so the type of '& (&r)' is *also* '&int' because of the
sugaring rules above. I've fixed this by changing the type of the
expression '&r' from '&int' to '*int' which means the compile skips the
sugar when computing the outer & operator.
I think that's right.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 228 bytes
Desc: not available
Url : /pipermail/nickle/attachments/20040520/8d21f530/attachment.pgp
More information about the Nickle