[Issue 199] Label causes scope to collapse into parent
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed May 29 03:53:29 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=199
--- Comment #12 from monarchdodra at gmail.com 2013-05-29 03:53:27 PDT ---
(In reply to comment #11)
> (In reply to comment #10)
>
> > - Potentially creates different behavior from C code.
>
> What are the conditions for it to create different behaviour? Maybe you can
> show two programs, in C and D, that behave differently.
This program for example, will behave differently in C and D:
--------
--------
int i = 3;
void main()
{
{
int some_condition = 1;
if ( some_condition )
goto block_end;
/* dummy code */
} block_end:
{
int i = 7;
printf("%i", i); //Local i
}
printf("%i", i); //Global i (?)
}
--------
C prints: "70"
D prints: "77"
--------
The conditions needed to create it is mostly just un-expected shadowing. This
one shows difference with C, but even without C, the behavior is not what would
have been expected from a D developer anyway.
The issue can also be reproduced in member functions, that have local variables
that shadow members. The shadowing will outlive its scope, and create
unexpected behavior.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list