B
bartc
[Be able to write a.b instead of a->b]
My 'problem' is probably a red herring. I just tried this auto-deference
change on a not-so hypothetical language. It works. And it does hang on
circular references (until I put in a deref limit anyway).
I still contend that auto-dereferencing of struct pointers is better suited
to a dynamic language than a static one.
Suppose you start off in C with a type of say *T. If you take the address of
this, the type is **T. If you dereference *T, you get type T. All very
strict and proper.
Now start off with a type of say T in a dynamically typed language. If you
take the address of this, the type is still T. If you dereference T, you get
type T still! This is as far as the compiler is concerned of course.
That's why I'm less concerned with auto-derefencing of these pointers in the
more informal dynamic language than in C:
struct point{int x,y;};
struct point a = {10,20};
struct point *b = &a;
struct point **c = &b;
struct point ***d = &c;
int i;
i=(***d).x;
i=d.x; /* Doesn't look right */
i=a.x;
This seems to be the wrong way round. You say the auto-dereference in
C would not be appropriate but it might be in a language with
dynamic typing but then you show a problem that C would not have and
the hypothetical dynamic language would.
My 'problem' is probably a red herring. I just tried this auto-deference
change on a not-so hypothetical language. It works. And it does hang on
circular references (until I put in a deref limit anyway).
I still contend that auto-dereferencing of struct pointers is better suited
to a dynamic language than a static one.
Suppose you start off in C with a type of say *T. If you take the address of
this, the type is **T. If you dereference *T, you get type T. All very
strict and proper.
Now start off with a type of say T in a dynamically typed language. If you
take the address of this, the type is still T. If you dereference T, you get
type T still! This is as far as the compiler is concerned of course.
That's why I'm less concerned with auto-derefencing of these pointers in the
more informal dynamic language than in C:
struct point{int x,y;};
struct point a = {10,20};
struct point *b = &a;
struct point **c = &b;
struct point ***d = &c;
int i;
i=(***d).x;
i=d.x; /* Doesn't look right */
i=a.x;