Am 22.06.2018 um 10:12 schrieb Ryan Joseph:

On Jun 22, 2018, at 12:24 PM, Sven Barth via fpc-pascal 
<fpc-pascal@lists.freepascal.org> wrote:

If $Assertions is set to Off the complete Assert() line will be absent from the 
compiled code.

Good to know thanks.


Here’s an example of something I’ve seen for debugging. I think that was kind 
of cool you could print types like that and I’m not sure how that would work in 
Pascal if at all. Maybe some RTTI magic perhaps.

{$define typestr(t):='#t: '+IntToStr(sizeof(#t))}

program macro_test;
uses
        SysUtils;

type
        MyRecord = record
                x, y, z: single;
        end;

begin
        writeln(typestr(MyRecord)); // MyRecord: 12
end.
In trunk that can be done rather nicely:

=== code begin ===

program ttest;

{$mode objfpc}

uses
  TypInfo;

type
  TMyRecord = record
    x, y, z: Single;
  end;

generic function TypeStr<T>: String;
var
  ti: PTypeInfo;
begin
  ti := PTypeInfo(TypeInfo(T));
  WriteStr(Result, ti^.Name, ': ', SizeOf(T));
end;

begin
  Writeln(specialize TypeStr<TMyRecord>);
end.

=== code end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to