digitalmars.D.bugs - version'd else-if
- derick_eddington nospam.yashmoo.com Jun 01 2005
- Derek Parnell <derek psych.ward> Jun 01 2005
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> Jun 02 2005
- derick_eddington nospam.yashmoo.com Jun 02 2005
- zwang <nehzgnaw gmail.com> Jun 01 2005
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
Jun 01 2005
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
Jun 01 2005
"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!
Jun 02 2005
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
Jun 02 2005
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
Jun 01 2005









derick_eddington nospam.yashmoo.com 