First, I wrote a bad example, and thanks to Michal for correcting me.
SomeStruct *const is indeed a constant field containing a pointer.
const SomeStruct * is a field pointing to a shallow read-only structure.
Michal is also correct that the entire const notion in C is advisory
and subject to being cast away. I wasn't trying to appeal to the C
type system here; I was only trying to express the problem in a
language syntax that everyone here presumably knows already.
On Wed, Mar 10, 2010 at 1:59 PM, Michal Suchanek <[email protected]> wrote:
> In the general case anything on RHS of an assignment can be non-const.
It is true that the RHS of an assignment can be non-const, but that is
not the general case. A more precise statement is that if an
assignment targets a slot having type (mutable S), where S is a value
type, then the expression on the RHS of the assignment must produce a
result that is copy-compatible with (shallow-readonly S). That is: the
type of the assignment operator is:
Assign(mutable S by reference, shallow-readonly S by reference)
> Interoperability with other languages is a nice thing but again: what
> does it give us to have a name for a half-working feature of some
> other language?
Serious answer: the ability to clearly express the fact that we are
constrained by a deficient contract, and must be aware of its
deficiencies.
> SomeStruct * const p is also called reference by another name...
The SomeStruct * is the reference. The "p" is the containing field,
and the constant-ness of that field has nothing to do with whether the
SomeStruct * is a reference.
shap
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev