I'm trying to port opensource C++ code into my own Pascal application.
Specifically, I'm using libredwg source to read an AutoCAD drawing file so that I can extract text attributes and populate a database using Lazarus.
char*
copy_bytes_16(char *dst, char *src)
{
*(uint64_t*)dst = *(uint64_t*)(src + 8);
*(uint64_t*)(dst + 8) = *(uint64_t*)src;
return dst + 16;
}
If I write the following Pascal code, is it equivalent? Obviously I would call the Procedure with copy_bytes(dst,src,posd,poss,16):
procedure copy_bytes(var dest: array of byte; src: array of byte; dp: integer; sp: integer; n: integer);
var
i, j: integer;
begin
i:=n+sp-1;
while i<n do
begin
dest[dp]:=src[i];
Inc(dp);
Dec(i);
end;
end;
The source also uses other functions to do a similar job, for example:
char*
copy_bytes_3(char *dst, char *src)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
return dst + 3;
}
Which I'm hoping to call using copy_bytes(dst,src,posd,poss,3):
I'd obviously increment pos_d and pos_s by the relevant amount. Is this feasible?