June 14, 2005 Re: mixing static if and if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | "Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:d8mag8$p52$1@digitaldaemon.com... > Thomas Kuehne wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > Is the following code legal, illegal or undefined? > > > > void test(){ > > const int a; > <snip> > > Good question. Should it be legal to declare a const without a value? Sure. It gets set to the default initializer for the type. |
June 17, 2005 Re: mixing static if and if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Stewart Gordon schrieb am Tue, 14 Jun 2005 10:43:04 +0100: > Thomas Kuehne wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Thomas Kuehne schrieb am Fri, 10 Jun 2005 23:08:54 +0200: >> >>> >>>Unknown W. Brackets schrieb am Fri, 10 Jun 2005 13:51:00 -0700: >>> >>>>Well, imho, that *should* be exactly the same as: >>>> >>>>void test() >>>>{ >>>> const int a; >>>> int b; >>>> >>>> if (b == 1) >>>> { >>>> } >>>> else // <-- this is the else I'm talking about. >>>> // **A** { >>>> static if (a == 2) >>>> { >>>> int c; // <-- visible inside whole else above. >>>> } >>>> else >>>> { >>>> // One couldn't use c here, though. >>>> if (b == 3) >>>> { >>>> } >>>> } >>>> // **B** } >>> >>> b+=c; >>> >>>>} >>>> >>>>If it's not currently, I'd say that it's the bug. >>> >>>Now add "b+=c;" to the end. >>>Before the rewrite b and c were declared in the same scope. >>>After the rewrite b and c are declared in different scopes. >> >> Allright, the scopeless "static if" can be a bit confusing at first. Remove the brackets A and B and everything turns legal and documented. ><snip> > > Legal? The outermost else block is of a normal if, not a static if, and therefore it creates a scope. Why should whether the body is a BlockStatement or not make a difference? It makes no sense, since whether or not c is declared would depend at runtime on whether b == 1. > > Documented? Where? "if" and "else if" open new scopes. "static if" and "else static if" don't open new scopes. { // scope:1 if(a) // scope:1.2 ... else if(b) // scope:1.3 ... else static if(c) // scope:1 ... else // scope:1.4 ... } Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCsxAX3w+/yD4P9tIRAoa6AJ98andjl0cxgPqTGzSYYHEI0TpmhQCdFCB0 K+ZEm6zUKVvuEJ5/g6BdOXQ= =0x5q -----END PGP SIGNATURE----- |
June 20, 2005 Re: mixing static if and if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | Thomas Kuehne wrote: <snip> > "if" and "else if" open new scopes. > "static if" and "else static if" don't open new scopes. > > { // scope:1 > if(a) // scope:1.2 > ... > else if(b) // scope:1.3 > ... > else static if(c) // scope:1 > ... > else // scope:1.4 > ... > } Not quite: (a) the 'else' in 'else static if' above belongs to the non-static if above it, and so the 'else' itself opens a scope. (b) the final 'else' belongs to a 'static if', so it doesn't create a scope. So in fact, it's like this { // scope:1 if(a) // scope:1.1 ... else // scope:1.2 if(b) // scope:1.2.1 ... else // scope:1.2.2 static if(c) // scope:1.2.2 ... else // scope:1.2.2 ... } When you have 'else if', you can pretend that the scope just inside the 'else' doesn't exist, as long as you don't try to mix static and non-static ifs at the same indentation level. Thus { // scope:1 if(a) // scope:1.1 ... else if(b) // scope:1.2 ... else // scope:1.3 static if(c) // scope:1.3 ... else // scope:1.3 ... } Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
June 20, 2005 Re: mixing static if and if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | On Mon, 20 Jun 2005 10:28:07 +0100, Stewart Gordon wrote: > Thomas Kuehne wrote: > <snip> >> "if" and "else if" open new scopes. >> "static if" and "else static if" don't open new scopes. >> >> { // scope:1 >> if(a) // scope:1.2 >> ... >> else if(b) // scope:1.3 >> ... >> else static if(c) // scope:1 >> ... >> else // scope:1.4 >> ... >> } > > Not quite: > > (a) the 'else' in 'else static if' above belongs to the non-static if > above it, and so the 'else' itself opens a scope. > (b) the final 'else' belongs to a 'static if', so it doesn't create a scope. > > So in fact, it's like this > > { // scope:1 > if(a) // scope:1.1 > ... > else // scope:1.2 > if(b) // scope:1.2.1 > ... > else // scope:1.2.2 > static if(c) // scope:1.2.2 > ... > else // scope:1.2.2 > ... > } > > When you have 'else if', you can pretend that the scope just inside the 'else' doesn't exist, as long as you don't try to mix static and non-static ifs at the same indentation level. Thus > > { // scope:1 > if(a) // scope:1.1 > ... > else if(b) // scope:1.2 > ... > else // scope:1.3 > static if(c) // scope:1.3 > ... > else // scope:1.3 > ... > } > > Stewart. The more that I see 'static if', the more I think it is really dumb. Not the concept, which is just great, but the syntax. It is almost like it was purposefully designed to be as confusing and obscure as possible. I would argue that a *single* token for 'static if' and another for 'static else' would make it much easier to use. Some token names that indicate a compile-time action would be useful too. -- Derek Parnell Melbourne, Australia 20/06/2005 9:00:23 PM |
June 20, 2005 Re: mixing static if and if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | What about version else then? Or, I guess, versionelse :P.
Personally, I like else just fine, and I think the syntax is very understandable. I guess it's all about how you lay it out, and how you think about it.
To me, else means just that - it's not a part of if, to me, but rather... "else".
-[Unknown]
> On Mon, 20 Jun 2005 10:28:07 +0100, Stewart Gordon wrote:
>
>
>>Thomas Kuehne wrote:
>><snip>
>>
>>>"if" and "else if" open new scopes.
>>>"static if" and "else static if" don't open new scopes.
>>>
>>>{ // scope:1
>>> if(a) // scope:1.2
>>> ...
>>> else if(b) // scope:1.3
>>> ...
>>> else static if(c) // scope:1
>>> ...
>>> else // scope:1.4
>>> ...
>>>}
>>
>>Not quite:
>>
>>(a) the 'else' in 'else static if' above belongs to the non-static if above it, and so the 'else' itself opens a scope.
>>(b) the final 'else' belongs to a 'static if', so it doesn't create a scope.
>>
>>So in fact, it's like this
>>
>>{ // scope:1
>> if(a) // scope:1.1
>> ...
>> else // scope:1.2
>> if(b) // scope:1.2.1
>> ...
>> else // scope:1.2.2
>> static if(c) // scope:1.2.2
>> ...
>> else // scope:1.2.2
>> ...
>>}
>>
>>When you have 'else if', you can pretend that the scope just inside the 'else' doesn't exist, as long as you don't try to mix static and non-static ifs at the same indentation level. Thus
>>
>>{ // scope:1
>> if(a) // scope:1.1
>> ...
>> else if(b) // scope:1.2
>> ...
>> else // scope:1.3
>> static if(c) // scope:1.3
>> ...
>> else // scope:1.3
>> ...
>>}
>>
>>Stewart.
>
>
> The more that I see 'static if', the more I think it is really dumb. Not
> the concept, which is just great, but the syntax. It is almost like it was
> purposefully designed to be as confusing and obscure as possible.
>
> I would argue that a *single* token for 'static if' and another for 'static
> else' would make it much easier to use. Some token names that indicate a
> compile-time action would be useful too.
>
|
Copyright © 1999-2021 by the D Language Foundation