Created
November 22, 2012 05:08
-
-
Save tangentstorm/4129499 to your computer and use it in GitHub Desktop.
structured unions with RECORD ... CASE in free pascal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{$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