On Sat, 28 Nov 2009 15:23:13 -0800 (PST)
Popog <
pop...@gmail.com> wrote:
> Also, GorgonZola, the suggestions you've made confuse me to no end,
> could you give some theoretical examples?
i am in line with you that const is the most profiling solution.
however, if it doesn't fit into the language, you are stuck with the
"Dan and Pete" problem and have to develop a sane type (possibly per
case) to share it between the two (own and untrusted) packages.
based on this, i just thought that having a general pointer type with a
general interface could help a bit because it doesn't force the
programmer to write *wrappers* for all the types he wants to share
with "untrusted" code.
the problem is that this "protected pointer" also must be implemented
into the language because if it is derived from the "normal" pointer,
it inherits too much functionality. the protected pointer should only
be able to serve the value of the target object. it should not be
otherwise addressable, and this should be checked at compile time to
not make exception handling a necessity.
we can now argue if the protected and the normal pointer shall behave
the same syntactically. in my example, i gave the protected pointer an
interface and a method. lets call this method GetValue. this method
throws back a value corresponding to the type the protected pointer
is declarated for. here should be no difference to the normal pointer.
possibly it's better to not give the protected pointer such a method
but make it usable like the normal pointer. this eases the
implementation a lot i think.
given that, one can use the protected pointer the same way one can use
the normal pointer except that one can only read from but not write
to it:
i := 5; // TODO: needs explanantion
nptr := &i; // nptr: normal pointer
pptr := °i; // pptr: protected pointer
*nptr = 6; // works!
*pptr = 7; // compile-time error: dereferencing a protected pointer
pptr = nptr; // works similar to using const in C
such a pointer could be used in a lot of cases, not only the "Dan and
Pete" problem. for example, think of a spreadsheet that supports a
"read-only" mode. one could just switch the pointers internally.
however, this leaves open how to pass the pointers to functions.
because they are of distinct type there is still a need for the
definition of an interface that is compatible to both pointer types.
the compiler would have to track if a function using this interface is
going to write to a protected pointer in a certain situation. am not
shure how to manage this sanely.
--
GorgonZola <
gorgo...@online.de>