January 02, 2008 Re: DMD 1.025 and 2.009 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote: > New const/invariant/enum in 2.009! > > http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.025.zip > > http://www.digitalmars.com/d/changelog.html http://ftp.digitalmars.com/dmd.2.009.zip Finally, I can try to break it. It was no fun too break something that was already thrown out ( http://www.digitalmars.com/d/archives/digitalmars/D/Invariants_broken_with_out_cast_63199.html ). |
January 12, 2008 Re: DMD 1.025 and 2.009 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tue, 01 Jan 2008 12:37:38 +0300, Walter Bright <newshound1@digitalmars.com> wrote: > New const/invariant/enum in 2.009! I have tried this sample: import std.stdio; class Notifier { int i; this( int i_value ) { i = i_value; } } class Message { public Notifier notifier; this( Notifier notifier_object ) { notifier = notifier_object; } } void main() { void show( Message m ) { writefln( &m.notifier, ": ", m.notifier.i ); } auto m1 = new Message( new Notifier( 1 ) ); show( m1 ); auto m2 = new invariant(Message)( new Notifier( 2 ) ); show( m2 ); m2.notifier = new Notifier( 3 ); show( m2 ); } and got: 882FF8: 1 882FD8: 2 882FD8: 3 Why m2 is not an invariant object? -- Regards, Yauheni Akhotnikau |
January 12, 2008 Re: DMD 1.025 and 2.009 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to eao197 | eao197 wrote: I've modified 3 lines in your main function: > void > main() > { > void show( Message m ) void show( in Message m ) > { > writefln( &m.notifier, ": ", m.notifier.i ); writefln( cast(Notifier*)&m.notifier, ": ", m.notifier.i ); > } > > auto m1 = new Message( new Notifier( 1 ) ); > show( m1 ); > > auto m2 = new invariant(Message)( new Notifier( 2 ) ); auto m2 = cast(invariant) new Message( new Notifier( 2 ) ); > show( m2 ); > m2.notifier = new Notifier( 3 ); > show( m2 ); > } > With these changes, I get the error "Error: cannot modify const/invariant m2.notifier". |
January 12, 2008 Re: DMD 1.025 and 2.009 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to torhu | On Sat, 12 Jan 2008 23:26:58 +0300, torhu <no@spam.invalid> wrote:
> eao197 wrote:
> I've modified 3 lines in your main function:
>
>> void
>> main()
>> {
>> void show( Message m )
> void show( in Message m )
>
>> {
>> writefln( &m.notifier, ": ", m.notifier.i );
> writefln( cast(Notifier*)&m.notifier, ": ", m.notifier.i );
>
>> }
>> auto m1 = new Message( new Notifier( 1 ) );
>> show( m1 );
>> auto m2 = new invariant(Message)( new Notifier( 2 ) );
> auto m2 = cast(invariant) new Message( new Notifier( 2 ) );
>
>> show( m2 );
>> m2.notifier = new Notifier( 3 );
>> show( m2 );
>> }
>>
>
> With these changes, I get the error "Error: cannot modify const/invariant m2.notifier".
But what 'new invariant(Message)' is supposed to do? I can't find it in the docs.
|
January 12, 2008 Re: DMD 1.025 and 2.009 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to naryl | naryl wrote:
> But what 'new invariant(Message)' is supposed to do? I can't find it in the docs.
As far as I know, it doesn't do anything. DMD allows some syntaxes that have no effect. It's a bit confusing sometimes.
|
Copyright © 1999-2021 by the D Language Foundation