Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Pascal

Idiom #94 Print the type of a variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

{$mode objfpc}{$H+}
{$ModeSwitch ImplicitFunctionSpecialization }
 
generic procedure PrintTypeOfX<T>(const X: T);
var
  tk: TTypeKind;
begin
  tk := System.GetTypeKind(X);
  writeln(tk);
end;

Requires fpc >= 3.3.1.
(type x)

New implementation...
< >
programming-idioms.org