4 Oct 05:07
Re: Revisit synonyms and references / typing
Slawomir Lisznianski <slisznianski <at> c2-lang.org>
2004-10-04 03:07:55 GMT
2004-10-04 03:07:55 GMT
edA-qa wrote:
> In my previous statemtn about references and instances, I am of the
> opinion, that in the way C2 works, the reference type has nothing to do
> with the actual instance type.
For clarification, an instance is characterized by a duet of type and
locality. Locality in turn determines types of references that are
allowed to refer to that instance. The relationship between a reference
type and locality of an instance is at the center of the C2 referencing
model.
An object shall only be accessed via a reference (or less safely via a
pointer). This is also true for value-types. Consider this example:
T localT;
Here, `localT' is a const reference to a stack object T (`localT' cannot
be rebound). Object T will be destroyed deterministically, that is, when
the `localT' reference goes out of scope.
T& st = localT; // error, there cannot be a synonym to a (value) type,
// only to a reference.
T local^& st = localT; // st: ok, synonym to reference to local T
One may think that the indexing operator brakes the "no synonym to
value-type" rule:
[]<T> ar[5](); // array of 5 Ts initialized with default constructor
(Continue reading)
RSS Feed