Path: utzoo!mnetor!uunet!portal!cup.portal.com!R_Tim_Coslet From: R_Tim_Coslet@cup.portal.com Newsgroups: comp.lang.modula2 Subject: Re: union types Message-ID: <4118@cup.portal.com> Date: 26 Mar 88 01:50:50 GMT References: <8803221947.AA00248@nrl-iws6.ARPA> Organization: The Portal System (TM) Lines: 35 XPortal-User-Id: 1.1001.4086 >I'm trying to build a Modula-2 interface to a C-library an have hit >a snag. Can anyone construct a suitable translation of: > > struct obj_name { > int obj_type; > union { > int id; > char *path; > } obj_id; > }; The direct equivalent of the above C in Modula-2 is.... ObjName : RECORD ObjType : INTEGER; CASE : BOOLEAN OF TRUE : id : INTEGER | FALSE : path : POINTER TO CHAR | END END This should creat the same data structure (and actually has one less identifier: obj_id). The key is that the TAG identifier is optional in the Variant CASE statement (alot of people never notice this!!!). I have not yet done any Modula-2 programming but I have been using Pascal for over eight years (the above is also applicable in Pascal). I verified this against Niklaus Wirth's book: Programming in Modula-2 Third, Corrected Edition Check the syntax diagrams in Appendix 4 (starting on page 189)