digitalmars.D - Multiversion conditional compilation
- Diego Lago (39/39) Jan 11 2006 Hello, I am testing D compiler with various things (in my spare time) an...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (10/14) Jan 11 2006 Walter doesn't want expressions in "version", so you need workarounds...
- Chad J (27/30) Jan 11 2006 Say it ain't so!
- J C Calvarese (18/48) Jan 11 2006 I'm afraid Anders is right. Many of us (myself included) have been askin...
- Chad J (12/33) Jan 11 2006 That line I wrote was in a static this() {} function, at the module
- Hasan Aljudy (4/47) Jan 11 2006 Maybe the spec doesn't say it directly, but, version = something is
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (20/32) Jan 12 2006 Not that it affects the issue, but for *this* particular example
- Carlos Santander (12/35) Jan 12 2006 Shouldn't it be:
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/19) Jan 12 2006 It was just an example, by the OP.
- Carlos Santander (8/32) Jan 12 2006 I know both things, but it just didn't make sense.
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (13/19) Jan 12 2006 Just like you said, it should be:
- Bruno Medeiros (17/53) Jan 13 2006 In natural language, in some cases they are not even boolean operators.
- S. Chancellor (4/38) Jan 21 2006 Sounds like you haven't been programming for long enough :) Eventually
Hello, I am testing D compiler with various things (in my spare time) and I was programming conditional compilation and I have found one thing that is not into the language: this is multiversion conditional compilation. See next source: //-------------------source-------------------- import std.stdio; alias char[] string; int main(string[] args) { version(win) { printf("Windows\n"); } version(lin) { printf("Linux"\n); } version(mac) { printf("Mac\n"); } /* version(win,lin) { printf("Windows & Linux\n"); } version(lin,mac) { printf("Linux & Mac\n"); } */ printf("All versions.\n"); return 0; } //-----------------end source--------------------- This portion of code compile witout problems but if I want to compile some piece of code for more than one version (commented source), I have to write it twice and, in the manner I show here, it can be done with less code. Could it be included into the language in next versions? Thanks for your attention, regards. -- Diego Lago beosman gmail.com P.D.: Sorry, I can't speak English very well, so it can be ununderstandable.
Jan 11 2006
Diego Lago wrote:This portion of code compile witout problems but if I want to compile some piece of code for more than one version (commented source), I have to write it twice and, in the manner I show here, it can be done with less code. Could it be included into the language in next versions?Walter doesn't want expressions in "version", so you need workarounds... version(win) version(lin) version = win_and_lin; version(win_and_lin) { printf("Windows & Linux\n"); } Just as an example of course, as the real ones are "Windows" and "linux" --anders
Jan 11 2006
Anders F Björklund wrote:Walter doesn't want expressions in "version", so you need workarounds...Say it ain't so! I would love to be able to use, at the very least, boolean operators inside of version. So like: version(D_InlineAsm_X86 && X86) I ran into this last night and ended up with version(D_InlineAsm_X86) { version(X86) { ... // cpu feature detection code here }} It works I suppose, but it sucks when you might end up having to nest 10 versions into each other! I'd much rather do something like version( D_InlineAsm_X86 && X86 && ... && ...) { ... } I also tried to do this: version(D_InlineAsm_X86) { version(X86) { version = UseX86Asm; } } but it gives me the following compiler errors (at that line): (condition) expected following version found '=' instead of statement I thought the spec allowed for that, and it seems to be the same kinda thing Anders just posted. I am using compiler version 0.142 (the latest AFAIK). So why the compiler errors?
Jan 11 2006
In article <dq4m1t$2per$1 digitaldaemon.com>, Chad J says...Anders F Björklund wrote:I'm afraid Anders is right. Many of us (myself included) have been asking for cooler version statements for years now. I've long since given up trying to get him to change his mind. :(Walter doesn't want expressions in "version", so you need workarounds...Say it ain't so!I would love to be able to use, at the very least, boolean operators inside of version. So like: version(D_InlineAsm_X86 && X86) I ran into this last night and ended up with version(D_InlineAsm_X86) { version(X86) { ... // cpu feature detection code here }} It works I suppose, but it sucks when you might end up having to nest 10 versions into each other! I'd much rather do something like version( D_InlineAsm_X86 && X86 && ... && ...) { ... } I also tried to do this: version(D_InlineAsm_X86) { version(X86) { version = UseX86Asm; } }That line works for me (at least it compiles). Here's a whole "program". It's trivial, but it does compiles: version(D_InlineAsm_X86) { version(X86) { version = UseX86Asm; } } void main() {}but it gives me the following compiler errors (at that line): (condition) expected following version found '=' instead of statementI suspect something else is generating that error. Sometimes the error messages seems to point to a particular line as the culprit, but the problem is really right after or right before. It's a good compiler, but it can't read minds. ;)I thought the spec allowed for that, and it seems to be the same kinda thing Anders just posted. I am using compiler version 0.142 (the latest AFAIK). So why the compiler errors?Well, actually, the latest compiler is 0.143 (just released a few hours ago), and that's what I tested it with it. So I guess you could try upgrading. But I suspect you just have a pesky extra semi-colon or an extra brace in a troublesome place. Good luck. I wish version could do more in the way you suggested, but I think the clever tricks can get us pretty close. jcc7
Jan 11 2006
J C Calvarese wrote:That line I wrote was in a static this() {} function, at the module scope. I moved it out of static this(), and it compiled just fine. So I think I figured out why it wasn't working - version = something; doesn't work within function bodies. try this: void main() { version = something; } Should fail to compile, same errors as previous post. I couldn't find this in the specs, is this a bug?I also tried to do this: version(D_InlineAsm_X86) { version(X86) { version = UseX86Asm; } }That line works for me (at least it compiles). Here's a whole "program". It's trivial, but it does compiles: version(D_InlineAsm_X86) { version(X86) { version = UseX86Asm; } } void main() {}but it gives me the following compiler errors (at that line): (condition) expected following version found '=' instead of statementI suspect something else is generating that error. Sometimes the error messages seems to point to a particular line as the culprit, but the problem is really right after or right before. It's a good compiler, but it can't read minds. ;)
Jan 11 2006
Chad J wrote:J C Calvarese wrote:Maybe the spec doesn't say it directly, but, version = something is called "VersionSpecification" and it's only allowed as a DeclDef; you can't have a DeclDef inside a FunctionBody.That line I wrote was in a static this() {} function, at the module scope. I moved it out of static this(), and it compiled just fine. So I think I figured out why it wasn't working - version = something; doesn't work within function bodies. try this: void main() { version = something; } Should fail to compile, same errors as previous post. I couldn't find this in the specs, is this a bug?I also tried to do this: version(D_InlineAsm_X86) { version(X86) { version = UseX86Asm; } }That line works for me (at least it compiles). Here's a whole "program". It's trivial, but it does compiles: version(D_InlineAsm_X86) { version(X86) { version = UseX86Asm; } } void main() {}but it gives me the following compiler errors (at that line): (condition) expected following version found '=' instead of statementI suspect something else is generating that error. Sometimes the error messages seems to point to a particular line as the culprit, but the problem is really right after or right before. It's a good compiler, but it can't read minds. ;)
Jan 11 2006
Chad J wrote:Or at least: "it hasn't been deemed important enough to include yet"...Walter doesn't want expressions in "version", so you need workarounds...Say it ain't so!I would love to be able to use, at the very least, boolean operators inside of version. So like: version(D_InlineAsm_X86 && X86) I ran into this last night and ended up with version(D_InlineAsm_X86) { version(X86) { ... // cpu feature detection code here }}Not that it affects the issue, but for *this* particular example the version(X86) is not needed. As Walter has already included that ? The new "D_InlineAsm_X86" is the same as the corresponding old code: version(X86) version (D_InlineAsm) { version = D_InlineAsm_X86; } There is no support for inline PPC asm in GDC yet (but there is in GCC), but I don't like adding certain arch to the language define like that... It makes sense in practice, but I would rather have both of them around. version (D_InlineAsm) { version(X86) version = D_InlineAsm_X86; version(PPC) version = D_InlineAsm_PPC; } --anders PS. Then again, "version(PPC)" is still missing from the list of versions ? (http://www.digitalmars.com/d/version.html) Along with: "version(Unix)" Both have been in "version(GNU)", i.e. GDC, for a rather long time now.
Jan 12 2006
Anders F Björklund escribió:Diego Lago wrote:Shouldn't it be: version(win) version = win_or_lin; version(lin) version = win_or_lin; version(win_or_lin) { printf("Windows & Linux\n"); } ? Otherwise, it doesn't make sense... -- Carlos Santander BernalThis portion of code compile witout problems but if I want to compile some piece of code for more than one version (commented source), I have to write it twice and, in the manner I show here, it can be done with less code. Could it be included into the language in next versions?Walter doesn't want expressions in "version", so you need workarounds... version(win) version(lin) version = win_and_lin; version(win_and_lin) { printf("Windows & Linux\n"); } Just as an example of course, as the real ones are "Windows" and "linux" --anders
Jan 12 2006
Carlos Santander wrote:Shouldn't it be: version(win) version = win_or_lin; version(lin) version = win_or_lin; version(win_or_lin) { printf("Windows & Linux\n"); } ? Otherwise, it doesn't make sense...It was just an example, by the OP. --anders PS. In your "corrected" example, printf("Windows | Linux\n");
Jan 12 2006
Anders F Björklund escribió:Carlos Santander wrote:I know both things, but it just didn't make sense. It's like boolean operators mean different things in programming languages than in natural languages: "women and children first", "do you want chicken or fish?". I understood that printf as saying "this is common for Windows and Linux". Anyway, when the OP actually codes, he'll see what he really wanted. -- Carlos Santander BernalShouldn't it be: version(win) version = win_or_lin; version(lin) version = win_or_lin; version(win_or_lin) { printf("Windows & Linux\n"); } ? Otherwise, it doesn't make sense...It was just an example, by the OP. --anders PS. In your "corrected" example, printf("Windows | Linux\n");
Jan 12 2006
Carlos Santander wrote:It's like boolean operators mean different things in programming languages than in natural languages: "women and children first", "do you want chicken or fish?". I understood that printf as saying "this is common for Windows and Linux".Correct, it turned out it was my mistake and not the original poster.Just like you said, it should be: version(win) version = win_or_lin; version(lin) version = win_or_lin; version(win_or_lin) { printf("Windows & Linux\n"); } Also, and even funnier, is that "win" or "lin" aren't right either. As per Walter's spelling prefs, it should be "Windows" and "linux" --andersversion(win,lin) { printf("Windows & Linux\n");
Jan 12 2006
Carlos Santander wrote:Anders F Björklund escribió:In natural language, in some cases they are not even boolean operators. For instance, 'or' when used in interrogatives has a "choice" meaning instead of a boolean meaning. Consider: "Is this blue and red?" Answers: 'Yes' or 'No' "Is this blue or red?" Answers: 'blue' or 'red' And 'and' has more of a meaning of "addition, aggregation", which is more general than booleanness, altough it still works like that. "Do this and that" Meaning: "Do this and do that", more of aggregation like, since imperatives don't even have truth values. -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."Carlos Santander wrote:I know both things, but it just didn't make sense. It's like boolean operators mean different things in programming languages than in natural languages: "women and children first", "do you want chicken or fish?". I understood that printf as saying "this is common for Windows and Linux".Shouldn't it be: version(win) version = win_or_lin; version(lin) version = win_or_lin; version(win_or_lin) { printf("Windows & Linux\n"); } ? Otherwise, it doesn't make sense...It was just an example, by the OP. --anders PS. In your "corrected" example, printf("Windows | Linux\n");
Jan 13 2006
On 2006-01-12 16:24:43 -0800, Carlos Santander <csantander619 gmail.com> said:Anders F Björklund escribió:Sounds like you haven't been programming for long enough :) Eventually you'll just answer True to those questions. -S.Carlos Santander wrote:I know both things, but it just didn't make sense. It's like boolean operators mean different things in programming languages than in natural languages: "women and children first", "do you want chicken or fish?". I understood that printf as saying "this is common for Windows and Linux". Anyway, when the OP actually codes, he'll see what he really wanted.Shouldn't it be: version(win) version = win_or_lin; version(lin) version = win_or_lin; version(win_or_lin) { printf("Windows & Linux\n"); } ? Otherwise, it doesn't make sense...It was just an example, by the OP. --anders PS. In your "corrected" example, printf("Windows | Linux\n");
Jan 21 2006