demo for using of qsort from lib and a little problem with it_(re)
Thu, 11 Sep 1997 15:58:46 +0200 (MEST)
Hallo, Sven! Hello, everybody!
According to Sven Hilscher:
>
> [...]
>
> type
> TestType = Integer; { works with Real, ShortInt, Integer, LongInt }
> { crashs with Byte }
> [...]
>
> function CompNum(var e1, e2: TestType):Integer;
> Var
> r : Real;
> begin
> r := e1 - e2;
> CompNum := Round(r);
> end;
Consider this with "TestType = Byte", then in `CompNum' we are subtracting
two `Byte' variables from each other. GPC chooses the result type to be
`Byte' again, so the result is never negative.
When I convert them to `Integer' by writing
r:= Integer ( e1 ) - Integer ( e2 );
it works. (First it did not work because of a bug in conversions among
integer types, but I could fix this.;-)
However, is this the correct behaviour? Or should the result type of a
subtraction be the "nearest" signed integer type - `ShortInt' in this
example? Then, what to do when subtracting two `LongestCard's, especially
in cases like "$FFFFFFFFFFFFFFFF - 2" where the result does not fit in
`LongestInt'?
BTW, Sven, this type casting problem does of course *not* explain the
crash you have observed when calling `qsort' on an array of bytes. :-(
Confused,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
maintainer GNU Pascal [970714] - http://home.pages.de/~gnu-pascal/ [970125]
Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)
HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada -
Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es