[fpc-pascal] Strange swap function, what does it do?
Bo Berglund
bo.berglund at gmail.com
Thu Aug 13 22:37:50 CEST 2020
I am working on the conversion of a service application from
Windows/Delphi to Linux/FPC.
When going through the code I found this procedure, which I do not
quite understand the workings of, can someone please explain how it
operates?
procedure Swap2(var Source);
var
H, L: word;
begin
H := Hi(word(Source));
L := Lo(word(Source));
word(Source) := (L * 256) + H;
end;
It is used in the code like this where Hd is a record and numSteps is
a word sized field:
Swap2(Hd.numSteps);
In other places when word sized variables need to be swapped
(Little/Big-endian conversions) it is done like this instead where
CmdProgNum is a smallint value and the built-in swap function is used:
FR.CmdProgNum := Swap(FR.CmdProgNum);
So the code uses a mix of these and I do not understand what the
strange looking function does...
--
Bo Berglund
Developer in Sweden
More information about the fpc-pascal
mailing list