Re: References and constant pointers



Hi

I would translate 'val x = ref 0'; as 'int x = 0', as 'x' is simply a
'int * const' in C by itself. This simply reflects that in ML stateful
computation is explicitly defined, whereas in C is implicit (everything
is carrying state)... and, besides, C programs derived from ML don't
have to be that complicated ;-)

cheers
Carlos Aya
p.s. let recommend you this http://www.info.ucl.ac.be/~pvr/book.html
for further reading about stateless/stateful programming paradigms.

cane wrote:
Hi, I'm trying to better understand the concept of reference in SML.
For what I've been able to grasp till now, and trying to draw an
analogy, a reference variable is much like a constant pointer in C, e.g.:

this SML snippet:

val x = ref 0;

Could be translated in C to something like:

int val = 0;
int* const x = &val;

Basically, you can modify the value of the pointed variable, but you
can't modify which variable the pointer points to.

So, standing the definitions above, you can do (SML): x := 1; as you can
do (C): *x = 1; but you cannot do (SML): val x = ref 1; (new binding for
the same identifier) as you cannot do (C): x = &val2; is that correct?

Thanks, bye.



.



Relevant Pages

  • Re: More pointer clarification
    ... If I declare a function and that function accepts int *x, ... The parameter receives a copy of a pointer which ... Your function 'doubleInt' does *not* modify ... For 'doubleInt' to modify what 'x' points to, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: K&R histogram help
    ... A pointer is a variable holding an address; you can modify the ... int main ... void foo; ...
    (comp.lang.c)
  • Re: accessor member functions and const
    ... > int main ... I suppose this is because a const object cannot be a non-const ... so it is not allowed to modify the class object. ... If it returned a pointer ...
    (alt.comp.lang.learn.c-cpp)
  • Re: K&R histogram help
    ... A pointer is a variable holding an address; you can modify the ... int main ...
    (comp.lang.c)
  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)