News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

find$() returns -1 if strings are identical

Started by jj2007, December 12, 2013, 04:27:32 AM

Previous topic - Next topic

jj2007

Not sure if this is intentional, but hlhelp.chm doesn't document this behaviour:
include \masm32\include\masm32rt.inc

.code
start:
mov esi, chr$("Masm32:")
print "esi=", 9, 9, 9, 9
print esi, 13, 10
print "find$(1, esi, 'Masm32:')=", 9
push find$(1, esi, "Masm32:")
print str$(eax), 13, 10
pop eax
exit eax
end start


Output:
esi=                            Masm32:
find$(1, esi, 'Masm32:')=       -1


MasmBasic Instr_(esi, "Masm32:") would return 1, and that seems to be a standard BASIC behaviour; but C/C++ might be different, of course.

I also had a weird problem with exit eax, being translated to invoke ExitProcess, 0 (with plain Masm32rt.inc), but I can't reproduce it now that I am on the other puter. Will check tomorrow if it's the same macros.asm on both machines 8)

MichaelW

The documentation for InString, called by find$, is in masmlib.chm under Zero Terminated String Functions.
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Thanks, Michael.

QuoteError Values

If the function fails, the following error values apply.
-1 = substring same length or longer than main string

There is an overview for Find$ at Wikipedia, but no info about the special case of identical strings.

GfaBasic and MasmBasic return 1. There is apparently no Instr() in C, but this workaround returns 0:
  char* s1="abcd";
  char* s2="abcd";
  char* result=strstr(s1, s2);
  int res=result-s1;
  printf("Instr identical=%i\n", res);

MichaelW

In addition to strstr I also tested FreeBASIC, QuickBASIC, and PB3 and they all returned 1, but given the problem with breaking existing code I doubt that this behavior is going to change.
Well Microsoft, here's another nice mess you've gotten us into.