D - [BUG] compiler segfault
- Ant (12/12) Mar 19 2004 void main()
- Ant (25/25) Mar 19 2004 On Fri, 19 Mar 2004 17:38:36 -0500, Ant wrote:
- Juan C (1/26) Mar 19 2004
- Walter (3/27) Mar 20 2004 Yes.
- Ant (17/23) Mar 20 2004 thank you.
- larry cowan (16/39) Mar 20 2004 In C,
- Ant (8/14) Mar 20 2004 [...]
- Vathix (9/34) Mar 20 2004 I would, except it's common practice to use in a for loop:
- Ant (3/21) Mar 20 2004 Yes, I did used it before....
- larry cowan (7/14) Mar 20 2004 Usage in the pre and post sections of a for loop is a bit different in t...
- Juan C (5/8) Mar 20 2004
- C (7/17) Mar 20 2004 Whats good comma operator use ? the only thing ive seen it used for =
- Ant (21/32) Mar 20 2004 Examples! Examples!
- larry cowan (6/25) Mar 21 2004 It appears to be evaluated from left-to-right, but the assignment is
- larry cowan (12/21) Mar 20 2004 The uninitiated shouldn't be programming, or should learn or be taught.
- larry cowan (17/40) Mar 20 2004 I tried a post a minute ago which didn't seem to take, so if this is a
- Ant (11/34) Mar 20 2004 thanks, maybe I can see the benefit of that some day...
- Manfred Nowak (12/14) Mar 21 2004 [...]
void main() { int i = 10; while ( false, (i-- > 0) ) { printf("i = %.*s\n", i); } } $ dmd T -I~/dmd/src/phobos Segmentation fault should it compile at all? Ant
Mar 19 2004
On Fri, 19 Mar 2004 17:38:36 -0500, Ant wrote: grrr :( I meant: void main() { int i = 10; while ( false, (i-- > 0) ) { printf("i = %d\n", i); } } $ dmd T -I~/dmd/src/phobos $ T i = 9 i = 8 i = 7 i = 6 i = 5 i = 4 i = 3 i = 2 i = 1 i = 0 is this valid? "while ( false, (i-- > 0) )" Ant
Mar 19 2004
In article <pan.2004.03.19.22.44.02.7718 yahoo.ca>, Ant says...On Fri, 19 Mar 2004 17:38:36 -0500, Ant wrote: grrr :( I meant: void main() { int i = 10; while ( false, (i-- > 0) ) { printf("i = %d\n", i); } } $ dmd T -I~/dmd/src/phobos $ T i = 9 i = 8 i = 7 i = 6 i = 5 i = 4 i = 3 i = 2 i = 1 i = 0 is this valid? "while ( false, (i-- > 0) )" Ant
Mar 19 2004
"Ant" <duitoolkit yahoo.ca> wrote in message news:pan.2004.03.19.22.44.02.7718 yahoo.ca...On Fri, 19 Mar 2004 17:38:36 -0500, Ant wrote: grrr :( I meant: void main() { int i = 10; while ( false, (i-- > 0) ) { printf("i = %d\n", i); } } $ dmd T -I~/dmd/src/phobos $ T i = 9 i = 8 i = 7 i = 6 i = 5 i = 4 i = 3 i = 2 i = 1 i = 0 is this valid? "while ( false, (i-- > 0) )"Yes.
Mar 20 2004
On Sat, 20 Mar 2004 12:16:07 -0800, Walter wrote:"Ant" <duitoolkit yahoo.ca> wrote in messagethank you. interesting: (from the manual) Expression: AssignExpression AssignExpression , Expression Anyone cares to explain why is it valid and what the use of "while ( false, (i-- > 0) )" ? thanks. what I was trying to do was something like "while ( !found && (i<lines.length) )" I don't know why I typed "," instead of "&&" but it cost me quite a bit of time to find the problem... Antis this valid? "while ( false, (i-- > 0) )"Yes.
Mar 20 2004
In C, (expr1, expr2, expr3) is a valid expression, and evaluates to the value of the rightmost subexpression. This is probably what is being carried forward. So (!found,i-- > 0) would evaluate !found, then replace its evaluation with that of i-- > 0, and use that - so it is NOT the same as (!found && i--> 0) There are possible uses of side-effects, so something like (i--,i++ > 0) would check for i-1 > 0 without changing it. Evaluation of a list of expressions like this should always be left-to-right, with only the side-effects being carried forward, the valuation is replaced with the next one until the rightmost is reached. In article <pan.2004.03.20.20.33.33.170646 yahoo.ca>, Ant says...On Sat, 20 Mar 2004 12:16:07 -0800, Walter wrote:"Ant" <duitoolkit yahoo.ca> wrote in messagethank you. interesting: (from the manual) Expression: AssignExpression AssignExpression , Expression Anyone cares to explain why is it valid and what the use of "while ( false, (i-- > 0) )" ? thanks. what I was trying to do was something like "while ( !found && (i<lines.length) )" I don't know why I typed "," instead of "&&" but it cost me quite a bit of time to find the problem... Antis this valid? "while ( false, (i-- > 0) )"Yes.
Mar 20 2004
On Sat, 20 Mar 2004 21:29:46 +0000, larry cowan wrote:In C, (expr1, expr2, expr3) is a valid expression, and evaluates to the value of the rightmost subexpression.[...]side-effects[...]side-effectsThank you. I didn't know. I believe I got it. should we vote to drop it!?... Ant
Mar 20 2004
Ant wrote:On Sat, 20 Mar 2004 21:29:46 +0000, larry cowan wrote:I would, except it's common practice to use in a for loop: for(i = 0; i < 5; i++, s++) { ... } The D way could be different, but what? for(i = 0; i < 5; {i++; s++;}) { ... } That's not too bad, especially since the comma operator can be a bit tricky to use. -- Christopher E. MillerIn C, (expr1, expr2, expr3) is a valid expression, and evaluates to the value of the rightmost subexpression.[...]side-effects[...]side-effectsThank you. I didn't know. I believe I got it. should we vote to drop it!?... Ant
Mar 20 2004
On Sat, 20 Mar 2004 17:07:34 -0500, Vathix wrote:Ant wrote:Yes, I did used it before.... AntOn Sat, 20 Mar 2004 21:29:46 +0000, larry cowan wrote:I would, except it's common practice to use in a for loop: for(i = 0; i < 5; i++, s++) { ... } The D way could be different, but what? for(i = 0; i < 5; {i++; s++;}) { ... } That's not too bad, especially since the comma operator can be a bit tricky to use.In C, (expr1, expr2, expr3) is a valid expression, and evaluates to the value of the rightmost subexpression.
Mar 20 2004
On Sat, 20 Mar 2004 17:07:34 -0500, Vathix wrote:Usage in the pre and post sections of a for loop is a bit different in that these don't get used as a value. You can in this way do if (x) a=1,b=2,c=3; without the braces or even if (x) f(x), g(x); to compress simple stuff and make it a quicker read. Not so great if they're not one-liners. The comma operator used in this way makes what would be multiple statements into a single one - the same effect as above in the for loop.I would, except it's common practice to use in a for loop: for(i = 0; i < 5; i++, s++) { ... } The D way could be different, but what? for(i = 0; i < 5; {i++; s++;}) { ... }
Mar 20 2004
<snip>if (x) a=1,b=2,c=3; without the braces or even if (x) f(x), g(x); to compress simple stuff and make it a quicker read. Not so great if they're not one-liners.</snip> That sure seems like abuse to me. Hard for the uninitiated to read -- read "obfuscated". The comma operator has its (few) uses, but this aint it.
Mar 20 2004
Whats good comma operator use ? the only thing ive seen it used for = 'reasonably' is C style macros. On Sun, 21 Mar 2004 05:08:34 +0000 (UTC), Juan C = <Juan_member pathlink.com> wrote:<snip>ad.if (x) a=3D1,b=3D2,c=3D3; without the braces or even if (x) f(x), g(x); to compress simple stuff and make it a quicker re=Not so great if they're not one-liners.</snip> That sure seems like abuse to me. Hard for the uninitiated to read -- =read "obfuscated". The comma operator has its (few) uses, but this aint it.-- = D Newsgroup.
Mar 20 2004
On Sun, 21 Mar 2004 05:08:34 +0000, Juan C wrote:<snip>Examples! Examples! but, but, it's broken: int f( int i ) { printf("i = %d\n", i); return i+14; } void f(int i, int j) { printf("i = %d\n", i+1); } void main() { int i = 1, j = 0; i = f( i , j ), f(( i , j )), f(( j , i )); } $ dmd T -I~/dmd/src/phobos T.d(16): cannot implicitly convert void to int Antif (x) a=1,b=2,c=3; without the braces or even if (x) f(x), g(x); to compress simple stuff and make it a quicker read. Not so great if they're not one-liners.</snip> That sure seems like abuse to me. Hard for the uninitiated to read -- read "obfuscated". The comma operator has its (few) uses, but this aint it.
Mar 20 2004
It appears to be evaluated from left-to-right, but the assignment is (trying to be) using the value of the leftmost expression. It looks like the assignment operator is taking precedence over the comma operator. That's correct, I believe. Add one more set of parens: i = ( f(i,j), f((i,j)), f((j,i)) ); In article <pan.2004.03.21.06.17.55.247300 yahoo.ca>, Ant says...but, but, it's broken: int f( int i ) { printf("i = %d\n", i); return i+14; } void f(int i, int j) { printf("i = %d\n", i+1); } void main() { int i = 1, j = 0; i = f( i , j ), f(( i , j )), f(( j , i )); } $ dmd T -I~/dmd/src/phobos T.d(16): cannot implicitly convert void to int Ant
Mar 21 2004
In article <c3j80i$h4$1 digitaldaemon.com>, Juan C says...<snip>The uninitiated shouldn't be programming, or should learn or be taught. Obfuscated is something far more esoteric and dense - intentionally so. Basically I agree with you, if (x) { a=1; b=2; c=3; } is perfectly fine. I was saying what could be done, not advocating it. Perhaps you'ld like to suggest some of those "few" uses for me. As an operator, where the value is taken from the rightmost and used, please. Except for pre and post sections of a for loop where it's a distinct convenience, but only that, and more of a separator than a replacement operator, I've probably only used it in 3 or 4 of my last 300,000 lines of code.if (x) a=1,b=2,c=3; without the braces or even if (x) f(x), g(x); to compress simple stuff and make it a quicker read. Not so great if they're not one-liners.</snip> That sure seems like abuse to me. Hard for the uninitiated to read -- read "obfuscated". The comma operator has its (few) uses, but this aint it.
Mar 20 2004
I tried a post a minute ago which didn't seem to take, so if this is a duplicate, at least I hope it's a better thought out one... In C, (expr1,expr2,expr3) would be evaluated left to right, with expr1 evaluated, then expr2 replacing the value, then expr3 which would be the final value of the expression. The value of (!found, i-- > 0) would be that of i-- > 0 with the !found value effectively ignored. Thus it's not the same as (!found && i-- > 0). There are uses where the side-effects of evaluating the left-side expressions are meaningful. This is not a really useful example, but (i--,i++ > 0) would test for i-1 > 0 without modifying the value of i. D seems to allow if (a=1,b=2,c=3,d=a+b+c,d == 6) and evaluates it correctly here where it is not really appropriate, but does not allow the same content in an assert statement where something like it might be useful. In article <pan.2004.03.20.20.33.33.170646 yahoo.ca>, Ant says...On Sat, 20 Mar 2004 12:16:07 -0800, Walter wrote:"Ant" <duitoolkit yahoo.ca> wrote in messagethank you. interesting: (from the manual) Expression: AssignExpression AssignExpression , Expression Anyone cares to explain why is it valid and what the use of "while ( false, (i-- > 0) )" ? thanks. what I was trying to do was something like "while ( !found && (i<lines.length) )" I don't know why I typed "," instead of "&&" but it cost me quite a bit of time to find the problem... Antis this valid? "while ( false, (i-- > 0) )"Yes.
Mar 20 2004
On Sat, 20 Mar 2004 21:56:23 +0000, larry cowan wrote:I tried a post a minute ago which didn't seem to take, so if this is a duplicate, at least I hope it's a better thought out one... In C, (expr1,expr2,expr3) would be evaluated left to right, with expr1 evaluated, then expr2 replacing the value, then expr3 which would be the final value of the expression. The value of (!found, i-- > 0) would be that of i-- > 0 with the !found value effectively ignored. Thus it's not the same as (!found && i-- > 0). There are uses where the side-effects of evaluating the left-side expressions are meaningful. This is not a really useful example, but (i--,i++ > 0) would test for i-1 > 0 without modifying the value of i. D seems to allow if (a=1,b=2,c=3,d=a+b+c,d == 6) and evaluates it correctly here where it is not really appropriate, but does not allow the same content in an assert statement where something like it might be useful.thanks, maybe I can see the benefit of that some day... void main() { assert(false, 0); } $ dmd T -I~/dmd/src/phobos T.d(3): found ',' when expecting ')' T.d(3): found '0' when expecting ';' following 'statement' T.d(3): found ')' instead of statement Ant
Mar 20 2004
Ant wrote: [...]assert(false, 0);[...]T.d(3): found ',' when expecting ')'[...] You detected an inconsistency: parse.c: | check(TOKlparen, "assert"); | e = parseAssignExp(); expression.html: | AssertExpression: | assert ( Expression ) So long!
Mar 21 2004