I am trying to translate a program from Pascal to C. However some statement in pascal confused me and i am not to sure what should I be using instead.
The statement in question is:
Now the main issues is the first line form: typform to me is a structure type but again i am not sure if i should be implementing a union, or a case statement
case form: typform of
subrangfrm: ( rangtyp: typtabptr;
enumfrm: ( maxenum: 0 .. 255);
arrayfrm: ( elemtyp,
recordfrm: ( lastfld: symtabptr;
tagfrm: ( tagfldp: symtabptr;
varntfrm: ( nxtvarnt,
setfrm: ( seteltyp: typtabptr;
That's object oriented programming and you're very unlikely to get it to work in C.
What we have here is the complex declaration of a type.
It's basically a union, or more specifically it's a sort of typesafe union where the compiler pretends that only certain members exist depending upon the variable that indicates the type held in the union.
You might later use a switch statement where that type is used, but here it's just the type declaration.
Thanks for the answer. Yeah it is a complex program, i am trying to make a compiler. So just to be clear if understand the best way to define it would be this way?
where typform is a enum ( i made it actually a typedef enum) this would be the best way to approach it?
typedef struct typrec