Skip to content

Instantly share code, notes, and snippets.

@tangentstorm
Created November 22, 2012 05:08
Show Gist options
  • Save tangentstorm/4129499 to your computer and use it in GitHub Desktop.
Save tangentstorm/4129499 to your computer and use it in GitHub Desktop.
structured unions with RECORD ... CASE in free pascal
{$mode objfpc}
unit caseclass;
interface uses classes;
type
kinds = ( kINT, kSYM, kSTR, kREF, kNUL, kOBJ );
RNode = record case kind : kinds of // valid pascal code
kINT : ( int : integer );
kSYM : ( sym : string );
kSTR : ( str : string );
kREF : ( ref : TObject );
kNUL : ( ptr : TObject );
kOBJ : ( obj : TObject );
end;
ONode = object case kind : kinds of // not allowed
kINT : ( int : integer );
kSYM : ( sym : string );
kSTR : ( str : string );
kREF : ( ref : TObject );
kNUL : ( ptr : TObject );
kOBJ : ( obj : TObject );
end;
CNode = class case kind : kinds of // not allowed
kINT : ( int : integer );
kSYM : ( sym : string );
kSTR : ( str : string );
kREF : ( ref : TObject );
kNUL : ( ptr : TObject );
kOBJ : ( obj : TObject );
end;
implementation
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment