goto skips declaration of variable

nrgyzer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 18 06:51:12 PDT 2014


Hi all,

I've the following code snipped:

import std.bigint;
void main(string[] args)
{
	BigInt i = "12345";
	if (args.length > 1)
	{
		goto Exit;
	}
	i = BigInt("67890");
	Exit:
		return;
}

When I try to compile this sample application I'm getting the 
following error:

sample.d(7): Error: goto skips declaration of variable 
sample.main.__ctmp1344 at sample.d(9)

I know that the error is caused by the line 'i = 
BigInt("67890")'. I also know that I can simply replace the 
goto-condition with something like this:

if (args.length == 0)
{
	i = BigInt("67890");
}

But that's not what I want because I've many BigInt-assignments 
in my real application. That would result in a very very deep, 
nested source structure and that really hurts. So, is there any 
solution how I can realize the BigInt-assignment after the 
goto-Command (or better: without skipping the declaration)?


More information about the Digitalmars-d-learn mailing list