www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Weird bug

reply kinghajj <kinghajj_member pathlink.com> writes:
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
next sibling parent reply Regan Heath <regan netwin.co.nz> writes:
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
parent reply kinghajj <kinghajj_member pathlink.com> writes:
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
parent reply Derek Parnell <derek psych.ward> writes:
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...
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/


Changing 'char' to 'int' also causes your original code to work. -- Derek Melbourne, Australia 3/11/2004 3:43:05 PM
Nov 02 2004
parent kinghajj <kinghajj_member pathlink.com> writes:
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 PM

OK, 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
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
It's definitely a compiler bug.
Nov 03 2004
parent reply "Walter" <newshound digitalmars.com> writes:
And I have it fixed now. Thanks!
Nov 03 2004
parent reply kinghajj <kinghajj_member pathlink.com> writes:
In article <cmbbk8$7q8$1 digitaldaemon.com>, Walter says...
And I have it fixed now. Thanks!

I guess I'll have to wait for v. 0.106
Nov 03 2004
parent "Walter" <newshound digitalmars.com> writes:
"kinghajj" <kinghajj_member pathlink.com> wrote in message
news:cmc012$1c7v$1 digitaldaemon.com...
 In article <cmbbk8$7q8$1 digitaldaemon.com>, Walter says...
And I have it fixed now. Thanks!

I guess I'll have to wait for v. 0.106

You can workaround for the time being by making it an int parameter, or inserting a call to printf("");
Nov 03 2004