Is this a bug? +goto
Neia Neutuladh
neia at ikeran.org
Tue Nov 6 01:05:04 UTC 2018
On Tue, 06 Nov 2018 00:33:56 +0000, MatheusBN wrote:
> Just to be clear, when you say "x exists at the label Q", you mean at
> the same scope, right?
The same or an outer scope. It's also invalid to write:
goto Y;
{
int x;
{
Y:
}
}
> That's interesting but a bit confusing isn't?
>
> And I found a bit strange that in such code, since "x" is never used,
> why it isn't skipped.
Because simple rules are usually easier to understand and implement.
> I know it's another language but in C at least in GCC there is no error
> over such code, so that's my confusion.
Because C is a horribly unsafe language, far beyond necessary to have a
low-level systems language.
In C++, if you skip over `int i = 10;` it's an error, but not if you skip
over `int i;`.
Similarly, if you skip over a class variable declaration without an
explicit initialization expression, if the class has a constructor or
destructor, it's an error.
In D, every variable of every type is initialized unless you opt out. The
compiler *could* let you skip over declarations that are void-initialized,
but there isn't a huge reason to do so.
More information about the Digitalmars-d-learn
mailing list