On 2021-06-16 23:49, Jean SUZINEAU via fpc-pascal wrote:
My best score is 67 kb after strip -s with the code below ... ;-)
Of course it will not work on every version of Windows.
program uptime;
function GetTickCount64: QWord; stdcall; external 'kernel32.dll';
function _2d( _i: Integer): String;
begin
Str( _i, Result);
if Length(Result) < 2 then Result:= '0'+Result;
end;
function FormatUpTime( _tc: QWord): String;
var
t, d, h, m, s: Integer;
sd: String;
begin
t:= _tc div 1000;
s:= t mod 60;
m:= (t div 60) mod 60;
h:= (t div 3600) mod 24;
d:= (t div 86400);
Result:= _2d(h)+':'+_2d( m)+':'+_2d( s);
if 0 = d then exit;
Str( d, sd);
Result:= sd+' '+Result;
end;
begin
WriteLn( FormatUpTime( GetTickCount64));
end.
I get half of your size, in particular 35840 bytes if compiling for
Win32 (a 64-bit version is 46592 bytes). The trick with manual import of
the respective Win32 API function is not necessary, the size doesn't
increase by adding 'uses Windows;' instead of the manual import.
D:\TEMP>fpc -XX -Xs uptime.pas
Free Pascal Compiler version 3.2.2 [2021/05/15] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling uptime.pas
Linking uptime.exe
33 lines compiled, 0.0 sec, 29760 bytes code, 1308 bytes data
D:\TEMP>dir uptime.exe
.
.
Directory of D:\TEMP
17.06.2021 12:18 35 840 uptime.exe
1 File(s) 35 840 bytes
Tomas
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal