Immutable + goto?

Derek Parnell derek at psych.ward
Thu Mar 19 14:20:30 PDT 2009


On Thu, 19 Mar 2009 15:07:33 +0000 (UTC), dsimcha wrote:

> import std.stdio;
> 
> uint bar = 0;
> 
> void main() {
>     start:
>     immutable uint foo = bar;
>     bar++;
>     writeln(foo);
>     goto start;
> }
> 
> foo changes in this case.  Is this a real bug, or is it considered undefined
> behavior to use goto in this way?

Hopefully I'm wrong but I believe that this is not a bug. It is incorrect
coding style.

As I've recently worked out from Walter's discussions, the compiler does
NOT enforce immutabilty or CAUSE things to be immutable. You should only
declare immutable those things that you know actually are already immutable
- like literals or stuff which is only ever assigned to once.

On the other hand, I think this should be a bug.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list