digitalmars.D - Weird bug
- kinghajj (35/35) Nov 02 2004 I've written a rot13 conversion function.
- Regan Heath (8/44) Nov 02 2004 No, but I have another clue, changin it to:
- kinghajj (2/51) Nov 02 2004
- Derek Parnell (6/64) Nov 02 2004 Changing 'char' to 'int' also causes your original code to work.
- kinghajj (15/20) Nov 02 2004 OK, I cleaned-up my code:
- Walter (1/1) Nov 03 2004 It's definitely a compiler bug.
I've written a rot13 conversion function. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} return ret; } For some reason, it doesn't work unless I add a "printf()" statement between the final "else if" clause and the return. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} printf(""); return ret; } Can anyone explain why this is happening??
Nov 02 2004
On Wed, 3 Nov 2004 00:25:34 +0000 (UTC), kinghajj <kinghajj_member pathlink.com> wrote:I've written a rot13 conversion function. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} return ret; } For some reason, it doesn't work unless I add a "printf()" statement between the final "else if" clause and the return. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} printf(""); return ret; } Can anyone explain why this is happening??No, but I have another clue, changin it to: char rot13_c(inout char ret) causes it to start working also. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 02 2004
huh... that's strange. But, it works for me to. In article <opsgu5capg5a2sq9 digitalmars.com>, Regan Heath says...On Wed, 3 Nov 2004 00:25:34 +0000 (UTC), kinghajj <kinghajj_member pathlink.com> wrote:I've written a rot13 conversion function. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} return ret; } For some reason, it doesn't work unless I add a "printf()" statement between the final "else if" clause and the return. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} printf(""); return ret; } Can anyone explain why this is happening??No, but I have another clue, changin it to: char rot13_c(inout char ret) causes it to start working also. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 02 2004
On Wed, 3 Nov 2004 03:05:43 +0000 (UTC), kinghajj wrote:huh... that's strange. But, it works for me to. In article <opsgu5capg5a2sq9 digitalmars.com>, Regan Heath says...Changing 'char' to 'int' also causes your original code to work. -- Derek Melbourne, Australia 3/11/2004 3:43:05 PMOn Wed, 3 Nov 2004 00:25:34 +0000 (UTC), kinghajj <kinghajj_member pathlink.com> wrote:I've written a rot13 conversion function. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} return ret; } For some reason, it doesn't work unless I add a "printf()" statement between the final "else if" clause and the return. /* Produces the rot13 of one letter. */ char rot13_c(char ret) { if(ret > 'A'-1 && ret < 'N') {ret += 13;} else if(ret > 'M' && ret < 'Z'+1) {ret -= 13;} else if(ret > 'a'-1 && ret < 'n') {ret += 13;} else if(ret > 'm' && ret < 'z'+1) {ret -= 13;} printf(""); return ret; } Can anyone explain why this is happening??No, but I have another clue, changin it to: char rot13_c(inout char ret) causes it to start working also. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 02 2004
In article <cm9nll$1bao$1 digitaldaemon.com>, Derek Parnell says...Changing 'char' to 'int' also causes your original code to work. -- Derek Melbourne, Australia 3/11/2004 3:43:05 PMOK, I cleaned-up my code: char rot13_c(int ret) { if(ret >= 'A' && ret <= 'M') ret += 13; else if(ret >= 'N' && ret <= 'Z') ret -= 13; else if(ret >= 'a' && ret <= 'm') ret += 13; else if(ret >= 'n' && ret <= 'z') ret -= 13; return ret; } still, I don't see why 'ret' needs to be int, but it works just fine.
Nov 02 2004
In article <cmbbk8$7q8$1 digitaldaemon.com>, Walter says...And I have it fixed now. Thanks!Cool, and thanks! I guess I'll have to wait for v. 0.106
Nov 03 2004
"kinghajj" <kinghajj_member pathlink.com> wrote in message news:cmc012$1c7v$1 digitaldaemon.com...In article <cmbbk8$7q8$1 digitaldaemon.com>, Walter says...You can workaround for the time being by making it an int parameter, or inserting a call to printf("");And I have it fixed now. Thanks!Cool, and thanks! I guess I'll have to wait for v. 0.106
Nov 03 2004