Sign in Join
FPDoc Onlineexperiment

CompareDWord function

In unit System

Compare 2 memory buffers DWord per DWord.

Declaration

pascal
function CompareDWord(const buf1; const buf2; len: SizeInt): SizeInt

Description

CompareDWord compares two memory regions buf1, buf2 on a DWord-per-DWord basis for a total of len DWords. (A DWord is 4 bytes).

The function returns one of the following values:

< 0
if buf1 and buf2 contain different DWords in the first len DWords, and the first such DWord is smaller in buf1 than the DWord at the same position in buf2.
0
if the first len DWords in buf1 and buf2 are equal.
> 0
if buf1 and buf2 contain different DWords in the first len DWords, and the first such DWord is larger in buf1 than the DWord at the same position in buf2.

Errors

None.

See also

Example: ex101

pascal
Program Example101;

{ Program to demonstrate the CompareDWord function. }

Const
  ArraySize     = 100;
  HalfArraySize = ArraySize Div 2;

Var
  Buf1,Buf2 : Array[1..ArraySize] of Dword;
  I : longint;

  Procedure CheckPos(Len : Longint);

  Begin
    Write('First ',Len,' DWords are ');
    if CompareDWord(Buf1,Buf2,Len)<>0 then
      Write('NOT ');
    Writeln('equal');
  end;


begin
  For I:=1 to ArraySize do
    begin
    Buf1[i]:=I;
    If I<=HalfArraySize Then
      Buf2[I]:=I
    else
      Buf2[i]:=HalfArraySize-I;
    end;
  CheckPos(HalfArraySize div 2);
  CheckPos(HalfArraySize);
  CheckPos(HalfArraySize+1);
  CheckPos(HalfArraySize + HalfArraySize Div 2);
end.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.