[Lazarus] Where is the System Unit source?

Sven Barth pascaldragon at googlemail.com
Wed Nov 14 17:18:22 CET 2012


Am 14.11.2012 16:58, schrieb Curt Carpenter:
> procedure test;
> var c: integer;
>       loc,hic: byte;
> begin
>     c := 1000;
>     hic := hi(c);
>     loc := lo(c);
> end;
>
> The result is always hic = 0 and loc = 0 for me.

Please provide a complete example (especially including an eventual 
"mode" directive as SizeOf(Integer) is different depending on the mode). 
I tested the following program here (using FPC 2.6.0) and I have no 
problems:

=== program begin ===

program hilotest;

{$mode fpc}

procedure test;
var c: integer;
       loc,hic: word;
begin
     c := 1000;
     hic := hi(c);
     loc := lo(c);
     Writeln(hic, ' ', loc);
end;

procedure test2;
var c: integer;
       loc,hic: byte;
begin
     c := 1000;
     hic := hi(c);
     loc := lo(c);
     Writeln(hic, ' ', loc);
end;

begin
   test;
   test2;
end.

=== program end ===

The following output is generated:

=== output begin ===

3 232
3 232

=== output end ===

If I change the mode from "fpc" to "objfpc" the output becomes:

=== output begin ===

0 1000
0 232

=== output end ===

>
> I have looked in ninl.pas as you suggested, and found the 
> in_lo_xxxxxx  items around line 2780 in that file.  I note that 
> in_lo_integer  and in_hi_integer do not appear among the items listed.
>
> In fpc/rtl/inc/system.inc,   I find Hi(b:byte): byte declared.
> in fpc/rtl/inc/systemh.inc, I find only declarations for hi and lo.
>
> I'm guessing that somehow hi(i:integer): byte  and lo(i:integer): byte 
> got dropped from the code base somehow (but remained in the fpc 
> documentation).
>
> Perhaps it's located somewhere that I have not looked yet?

It seems that you haven't read the declarations in systemh.inc correctly:

Function  lo(l : Longint) : Word;  [INTERNPROC: fpc_in_lo_long];

The "INTERNPROC" tells you that the function is a compiler intrinsic 
(and as such implemented in ninl.pas)

Regards,
Sven




More information about the Lazarus mailing list