Author Topic: String copairing in 763 vs 732  (Read 205 times)

GSAC3

  • Newbie
  • *
  • Posts: 16
    • View Profile
String copairing in 763 vs 732
« on: February 08, 2021, 12:16:43 AM »
Since string compares are now, apparently by default, done by uppercasing both strings before comparing, how do you now go about comparing strings on a case sensitive basis as was the norm in BCX 732?  After looking a a number of codes written in the 732 era, I have found that the major problem in each case of trying to recompile and run correctly under 761 is due to this change in comparing strings.

Robert

  • Hero Member
  • *****
  • Posts: 580
    • View Profile
Re: String copairing in 763 vs 732
« Reply #1 on: February 08, 2021, 02:41:07 AM »
Since string compares are now, apparently by default, done by uppercasing both strings before comparing, how do you now go about comparing strings on a case sensitive basis as was the norm in BCX 732?  After looking a a number of codes written in the 732 era, I have found that the major problem in each case of trying to recompile and run correctly under 761 is due to this change in comparing strings.

Hi Don:

A specific example would make your claim credible.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 749
    • View Profile
Re: String copairing in 763 vs 732
« Reply #2 on: February 08, 2021, 07:44:43 AM »
Since string compares are now, apparently by default, done by uppercasing both strings before comparing, how do you now go about comparing strings on a case sensitive basis as was the norm in BCX 732?  After looking a a number of codes written in the 732 era, I have found that the major problem in each case of trying to recompile and run correctly under 761 is due to this change in comparing strings.

Hi Don,

Comparing strings in C has traditionally been done using the standard library functions strcmp and stricmp.

strcmp is used to perform case-sensitive comparisons

stricmp is used to perform non-case-sensitive comparisons ( by comparing lower case versions of the strings )

For all case-sensitive string comparisons, BCX uses the compiler's standard library
implementation of the strcmp function.

For many years, BCX used its own version of strcmp ( str_cmp) which was a little faster than some compiler
library implementations.  Eventually, hardware and compiler improvements rendered the custom version
pointless and BCX 7.4.8 went back to using the standard library version of strcmp.

It's worth noting that throughout 2020, dozens, possibly hundreds, of single-character string comparisons
in the BCX translator were changed to pointer comparisons, in order to eliminate the overhead of those function
calls and, in return, provide the translator with a performance bump.  Perhaps your encryption work is triggering
a "corner case" in one or more of those comparisons.

In October 2020, I implemented the "??" operator which initially used the standard stricmp C function.
Eventually, stricmp was replaced with a new BCX function:  bcx_stricmp.

Hours of testing were performed before the string changes were rolled out in version 757 but it's possible
you have a "corner case" that we need to look at.  We would need you to provide a short, easy to understand
example that clearly demonstrates the failure.

Robert Wishlaw collaborated with me on the creation and testing of the locale-specific bcx_stricmp function,
in response to this eye-popping Microsoft article:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stricmp-wcsicmp-mbsicmp-stricmp-l-wcsicmp-l-mbsicmp-l?view=msvc-160

From which the following extract is noteworthy:

Because _stricmp does lowercase comparisons, it may result in unexpected behavior.

To illustrate when case conversion by _stricmp affects the outcome of a comparison, assume that you have the two strings JOHNSTON and JOHN_HENRY. The string JOHN_HENRY will be considered less than JOHNSTON because the "_" has a lower ASCII value than a lowercase S. In fact, any character that has an ASCII value between 91 and 96 will be considered less than any letter.

If the strcmp function is used instead of _stricmp, JOHN_HENRY will be greater than JOHNSTON.



« Last Edit: February 08, 2021, 01:34:46 PM by MrBcx »

GSAC3

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: String copairing in 763 vs 732
« Reply #3 on: February 08, 2021, 02:29:03 PM »
Kevin:

Many thanks for your detailed info on what has been happening with string compare functions in BCX since 732.

The change from str_cmp to strcmp seems to be the problem I am having based on the comparison translations and the compile error I am getting with the BCX 761 compile vs BCX 732 as illustrated i the attached results.  My question is, how do I solve this problem in the 761 case sensitive compiles of my 732 acceptable BCX code?

Don

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 749
    • View Profile
Re: String copairing in 763 vs 732
« Reply #4 on: February 08, 2021, 04:26:11 PM »
Don,

It looks like you found a parsing error that will require some investigation.


As a workaround, change string IF statements like this:

 IF COUNTERTEST$ => LT$ THEN

to this:

 IF COUNTERTEST$ =  LT$ OR  COUNTERTEST$ >  LT$ THEN


Robert

  • Hero Member
  • *****
  • Posts: 580
    • View Profile
Re: String copairing in 763 vs 732
« Reply #5 on: February 08, 2021, 04:30:28 PM »
Since string compares are now, apparently by default, done by uppercasing both strings before comparing, how do you now go about comparing strings on a case sensitive basis as was the norm in BCX 732?  After looking a a number of codes written in the 732 era, I have found that the major problem in each case of trying to recompile and run correctly under 761 is due to this change in comparing strings.

Thanks Don. It got broken in BCX 7.5.7. MrBCX will have fix up quick as a wink.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 749
    • View Profile
Re: String copairing in 763 vs 732
« Reply #6 on: February 08, 2021, 04:37:34 PM »
Thanks Don. It got broken in BCX 7.5.7. MrBCX will have fix up quick as a wink.

LOL ... I appreciate your vote of confidence ... it might well take several winks to track this down.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 749
    • View Profile
Re: String copairing in 763 vs 732
« Reply #7 on: February 08, 2021, 06:12:26 PM »
Don,

I have attached a BETA copy 764 in 32-bit format.

It correctly translates the following sample.

Please take this BETA for a spin on some of your code and report back.


Code: [Select]

DIM apples$
DIM grapes$

apples$ = "apples"
grapes$ = "grapes"

IF apples$ >= grapes$ then print "This should NOT print"
IF apples$ <= grapes$ then print "Yes -- apples are <= grapes"



GSAC3

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: String copairing in 763 vs 732
« Reply #8 on: February 08, 2021, 07:40:09 PM »
Kevin:

So far, your BETA fix looks good.  At least, my RBz code now compiles without error.  Am still having problems getting correct execution results of the main program though.Will be testing your fix more on several other programs.

Have now discovered what looks like a possible issue with the RND and/or the RANDOMIZE functions.  I am not sure yet but I am wondering if either of the functions have been changed or modified in some way since BCX732?  Has the algorithm for the PRN generator been changed since 732?

Don

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 749
    • View Profile
Re: String copairing in 763 vs 732
« Reply #9 on: February 08, 2021, 08:16:54 PM »
Kevin:

So far, your BETA fix looks good.  At least, my RBz code now compiles without error.  Am still having problems getting correct execution results of the main program though.Will be testing your fix more on several other programs.

Have now discovered what looks like a possible issue with the RND and/or the RANDOMIZE functions.  I am not sure yet but I am wondering if either of the functions have been changed or modified in some way since BCX732?  Has the algorithm for the PRN generator been changed since 732?

Don

Don -- Thanks for the update. 

RANDOMIZE with no parameters uses the timer() function as a seed to the C function srand. 

In other words:

RANDOMIZE and RANDOMIZE TIMER do the same thing.

Otherwise, you can pass whatever seed you want to RANDOMIZE, for example, RANDOMIZE 3.14159

The RND function changed from:

 IF Use_Rnd THEN
    IF Use_Library THEN FPRINT FP_WRITE, "// BCXRTLIB: rnd"
    FPRINT FP_WRITE, "float rnd (void)"
    FPRINT FP_WRITE, "{"
    FPRINT FP_WRITE, "  return (float)rand()/RAND_MAX;"
    FPRINT FP_WRITE, sENDBCXRTLIB$
  END IF


to

   IF Use_Rnd THEN
      FPRINT FP_WRITE, "float rnd (void)"
      FPRINT FP_WRITE, "{"
      FPRINT FP_WRITE, "  srand(GetTickCount()*rand());"
      FPRINT FP_WRITE, "  return (float)rand()/RAND_MAX;"
      FPRINT FP_WRITE, "}\n\n"
   END IF


Which I now see was not completely thought out, so I will revert it in 7.6.4.

The issue that I see now is that rnd() defeats any user supplied seed.

GSAC3

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: String copairing in 763 vs 732
« Reply #10 on: February 08, 2021, 09:52:35 PM »
Kevin:

Try compiling and executing the attached random number test program FIRST under BCX 742 and THEN3using BCX 764.

Don

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 749
    • View Profile
Re: String copairing in 763 vs 732
« Reply #11 on: February 08, 2021, 10:27:35 PM »
Kevin:

Try compiling and executing the attached random number test program FIRST under BCX 742 and THEN3using BCX 764.

Don

I've already reverted the RND function, so 742 and my current version of 764 produce the following:

♂3P↕C

Press any key to continue . . .

1234567890

Press any key to continue . . .


GSAC3

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: String copairing in 763 vs 732
« Reply #12 on: February 09, 2021, 01:20:55 PM »
Kevin:

Thanks to you and Robert for your help.

BCX764 with your last two fixes, seems to be working well now in both compiling and execution results with my RBz program which is very typical of several others I will now be trying to compile and execute with 764.

I don't normally don't use BCX's random number generator for serious encryption, but I do frequently use it for generating access keys to files.  So before your fix, the programs using it for this purpose could not locate the correct code segments to process.  Baring any other coding differences between 732 and 764 that I find, the two fixes you made should do the trick.

Don

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 749
    • View Profile
Re: String copairing in 763 vs 732
« Reply #13 on: February 09, 2021, 01:52:52 PM »
Kevin:

Thanks to you and Robert for your help.

BCX764 with your last two fixes, seems to be working well now in both compiling and execution results with my RBz program which is very typical of several others I will now be trying to compile and execute with 764.

I don't normally don't use BCX's random number generator for serious encryption, but I do frequently use it for generating access keys to files.  So before your fix, the programs using it for this purpose could not locate the correct code segments to process.  Baring any other coding differences between 732 and 764 that I find, the two fixes you made should do the trick.

Don

Glad to hear it ...

Moving BCX forward is like making an omelet ... gotta break a few eggs to get the job done.

GSAC3

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: String copairing in 763 vs 732
« Reply #14 on: February 09, 2021, 06:29:02 PM »
You guys are pretty damn good at making good omelets. Of course, having done it for more than 20 years now, you have a good leg up in the experience department. KEEP TRUCKING!