Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
June 01, 2005 version'd else-if | ||||
---|---|---|---|---|
| ||||
DMD 0.125 on Linux. : import std.stdio; : : void main (char[][] args) : { : if (args.length = 2) { : writefln("2"); : } : version (BUG) { : else if (args.length == 3) { : writefln("3"); : } : } : } $ dmd verelif.d verelif.d(9): found 'else' instead of statement verelif.d(13): unrecognized declaration $ dmd -version=BUG verelif.d verelif.d(9): found 'else' instead of statement verelif.d(13): unrecognized declaration |
June 01, 2005 Re: version'd else-if | ||||
---|---|---|---|---|
| ||||
Posted in reply to derick_eddington | On Wed, 1 Jun 2005 07:56:16 +0000 (UTC), derick_eddington@nospam.yashmoo.com wrote: > DMD 0.125 on Linux. > >: import std.stdio; >: >: void main (char[][] args) >: { >: if (args.length = 2) { >: writefln("2"); >: } >: version (BUG) { >: else if (args.length == 3) { >: writefln("3"); >: } >: } >: } > > $ dmd verelif.d > verelif.d(9): found 'else' instead of statement > verelif.d(13): unrecognized declaration > > $ dmd -version=BUG verelif.d > verelif.d(9): found 'else' instead of statement > verelif.d(13): unrecognized declaration The docs say that the body of a version block must be valid D statements, and 'else' never starts a valid D statement. So its not a bug. Try rearranging it thus ... void main (char[][] args) { if (args.length == 2) { writefln("2"); } else version (BUG) { if (args.length == 3) { writefln("3"); } } } -- Derek Melbourne, Australia 1/06/2005 6:39:25 PM |
June 01, 2005 Re: version'd else-if | ||||
---|---|---|---|---|
| ||||
Posted in reply to derick_eddington | derick_eddington@nospam.yashmoo.com wrote: > DMD 0.125 on Linux. > > : import std.stdio; > : > : void main (char[][] args) > : { > : if (args.length = 2) { > : writefln("2"); > : } > : version (BUG) { > : else if (args.length == 3) { > : writefln("3"); > : } > : } > : } > > $ dmd verelif.d > verelif.d(9): found 'else' instead of statement > verelif.d(13): unrecognized declaration > > $ dmd -version=BUG verelif.d > verelif.d(9): found 'else' instead of statement > verelif.d(13): unrecognized declaration > > This is not a bug. Your sample code violates the syntax defined in http://www.digitalmars.com/d/version.html ConditionalDeclaration: Condition DeclarationBlock Condition DeclarationBlock else DeclarationBlock DeclarationBlock: Declaration { Declarations } Declarations: Declaration Declaration Declarations ConditionalStatement: Condition Statement Condition Statement else Statement Condition: VersionCondition DebugCondition StaticIfCondition IfTypeCondition |
June 02, 2005 Re: version'd else-if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | "Derek Parnell" <derek@psych.ward> wrote in message news:g6j77wymnkft.9f9aw0m8symi$.dlg@40tude.net... > Try rearranging it thus ... > > void main (char[][] args) > { > if (args.length == 2) { > writefln("2"); > } > else > version (BUG) { > if (args.length == 3) { > writefln("3"); > } > } > } Might have to have an extra set of {} after the version statement - or else anything after the version statement, if BUG is not defined, will be the "else" statement! |
June 03, 2005 Re: version'd else-if | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | In article <d7npko$27fp$1@digitaldaemon.com>, Jarrett Billingsley says... > >"Derek Parnell" <derek@psych.ward> wrote in message news:g6j77wymnkft.9f9aw0m8symi$.dlg@40tude.net... >> Try rearranging it thus ... >> >> void main (char[][] args) >> { >> if (args.length == 2) { >> writefln("2"); >> } >> else >> version (BUG) { >> if (args.length == 3) { >> writefln("3"); >> } >> } >> } > >Might have to have an extra set of {} after the version statement - or else anything after the version statement, if BUG is not defined, will be the "else" statement! I wondered about that too at first but it's not at all just textually including like I was assuming before. version() is ConditionalStatement which is a Statement, and in this case it is always seen as the Statement of the 'else'. For example: >> void main (char[][] args) >> { >> if (args.length == 2) { >> writefln("2"); >> } >> else >> version (BUG) { >> if (args.length == 3) { >> writefln("3"); >> } >> } >> writefln("hmm"); >> } $ dmd verelif.d # no -version=BUG $ ./verelif hmm $ ./verelif abc 2 hmm |
Copyright © 1999-2021 by the D Language Foundation