C code to Pascal. ... just need to see if I'm correct

Hi, I have the following code in C:

char *strmov(register char *dst, register const char *src)
{
  while ((*dst++ = *src++)) ;
  return dst-1;
}

I translated the following to pascal as:

function strmov(dst : PChar; const src : PChar) : PChar;
var
  tmp_src : PChar;
begin
  tmp_src := src;
  while tmp_src^ <> #0 do
  begin
    dst^ := tmp_src^;
    inc(dst);
    inc(tmp_src);
  end;
  Result := dst - 1;
end;

Is my code correct ? ... assuming it is, is there any room for improvement without going asm ?

Thanks
delphi112497Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GloomyFriarCommented:
It looks like the code is correct.
0
GloomyFriarCommented:
Though not absolutely...
0
GloomyFriarCommented:
The C-code copy all the string including null-terminator and return pointer to null-terminator.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

GloomyFriarCommented:
But the PAS-code not copy null-terminator and return pointer to the last copied byte.
0
GloomyFriarCommented:
How about the following code:

function strmov(dst : PChar; const src : PChar) : PChar;
begin
   Result := PChar(dst + StrLen(StrCopy(dst, src)));
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
delphi112497Author Commented:
GloomyFriar, your code looks logically reasonable ... its by far simpler than mine.  THanks a lot!
0
GloomyFriarCommented:
The StrCopy will be faster than byte-by-byte copying for long strings because of it use dword copying.
0
robert_marquardtCommented:
To correct the Pascal Code make it a "repeat until"
Drop the const of the src param because C const is different from Pascal const.
That allows to remoce tmp_src
0
ChopinkeCommented:
or similarly to StrCopy

i := StrLen(src);
Move(src^, dst^, i);
Result := PChar(dst+i);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.