Re: [fpc-pascal] Will the size of an executable depend on the uses clause
Heh, how very cool. I wasn't aware powershell could do such things. All kinds of new things learned in this thread. Thanks for that. On 6/17/2021 5:08 AM, Jean SUZINEAU via fpc-pascal wrote: 10 kb of Powerbasic ... you're cheating, it's pascal here ;-) You can do this with just 1kb of PowerShell ... ( may be Pascal script could even be shorter ...) File uptime.ps1 : $MethodDefinition = @" [DllImport("kernel32")] public extern static UInt64 GetTickCount64(); "@ $Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name 'Kernel32' -Namespace 'Win32' -PassThru #milliseconds $tc= $Kernel32::GetTickCount64() # seconds $t= ($tc-$tc % 1000)/1000 $s= $t%60 # minutes $tm=($t-$s)/60 $m= $tm % 60 #hours $th=($tm-$m)/60 $h=$th % 24 #days $d=($th-$h)/24 $Result="{0:d2}:{1:d2}:{2:d2}" -f $h,$m,$s if ($d -ne 0) { $Result= "{0} {1}" -f $d,$Result } Write-Host $Result ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Will the size of an executable depend on the uses clause
Op 2021-06-16 om 23:49 schreef Jean SUZINEAU via fpc-pascal: My best score is 67 kb after strip -s with the code below ... ;-) The fact that you use "result" for function result indicates that you use a object pascal mode, and not the default. If you don't do that (compile in the default mode , fpc), I get 35,328 uptime.exe with FPC 3.2.2 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Will the size of an executable depend on the uses clause
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:1835 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
Re: [fpc-pascal] Will the size of an executable depend on the uses clause
10 kb of Powerbasic ... you're cheating, it's pascal here ;-) You can do this with just 1kb of PowerShell ... ( may be Pascal script could even be shorter ...) File uptime.ps1 : $MethodDefinition = @" [DllImport("kernel32")] public extern static UInt64 GetTickCount64(); "@ $Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name 'Kernel32' -Namespace 'Win32' -PassThru #milliseconds $tc= $Kernel32::GetTickCount64() # seconds $t= ($tc-$tc % 1000)/1000 $s= $t%60 # minutes $tm=($t-$s)/60 $m= $tm % 60 #hours $th=($tm-$m)/60 $h=$th % 24 #days $d=($th-$h)/24 $Result="{0:d2}:{1:d2}:{2:d2}" -f $h,$m,$s if ($d -ne 0) { $Result= "{0} {1}" -f $d,$Result } Write-Host $Result ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal