any news on const/invariant?

Leandro Lucarella llucax at gmail.com
Thu Nov 29 09:23:52 PST 2007


Steven Schveighoffer, el 28 de noviembre a las 23:02 me escribiste:
> "Walter Bright" wrote
> > Janice Caron wrote:
> >>> Also, C++ has const as both a storage class and a type constructor, and
> >>> yes, they have subtly different meanings. This doesn't seem to cause any
> >>> major problems.
> >>
> >> That's because C++ behaves as expected. If I declare
> >>
> >>     const int * f();
> >>
> >> then I get a function which returns a pointer to const int, /not/ a
> >> const member function which returns a pointer to mutable int.
> >
> > What is expected, or what you are *used* to? Let me put it another way, 
> > can you explain the difference between C++ const storage class and C++ 
> > const type constructors? There's a big semantic difference.
> 
> Let me reword Walter's point, as I think he didn't really get it across 
> completely :)
> 
> Let's say someone had never used C++ and it's const system.  Let's say that 
> person is a virgin coder starting to dabble in D.  Let's explain how const 
> works to him/her:
> 
> to declare that a type is constant, you do:
> 
> const(Type) x;
> 
> to declare that a method returns a const value, you do:
> 
> const(Type) f();
> 
> to declare that a method is constant, that is, it will not modify any 
> members of a class the method resides in, you do:
> 
> const Type f();
> 
> If that method returns a const type, then the method is declared as:
> 
> const const(Type) f();

This sounds right.

> for compatibility with C++ and C, you can also do:
> 
> const Type x;
> for a const type declaration, and
> 
> Type f() const
> for a const method declaration.

This is what it's confusing.
1) Why does D need C++ compatibility?
2) Here is were all possible confusion about "what does const Type f()
   const means?

Is in some places const Type x means const(Type) x and in other places it
doesn't, it's really confusing, specially when reading code that mix
styles.

I think C++ compatibility should be dropped.

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
CHINO ATRAPA COTORRAS
	-- Crónica TV



More information about the Digitalmars-d mailing list