Path: news.daimi.aau.dk!glad From: Rene Wenzel Schmidt Newsgroups: comp.lang.beta Subject: Re: UNION in BETA Date: 20 Mar 1996 10:07:24 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 55 Approved: mailtonews@daimi.aau.dk Distribution: world Message-ID: <4iolcs$5lo@gjallar.daimi.aau.dk> NNTP-Posting-Host: daimi.daimi.aau.dk > From news@gjallar.daimi.aau.dk Wed Mar 20 08:45:45 1996 > To: usergroup@mjolner.dk > From: Kolbjorn.Aambo@ub.uio.no (Kolbj\xrn Aamb\x) > Subject: UNION in BETA > Date: Tue, 19 Mar 1996 12:08:15 +0100 > Nntp-Posting-Host: ubmac86.uio.no > X-Charset: LATIN1 > X-Char-Esc: 29 > > In C I can define > > struct cell { > union { > long int; > short int n[2]; > unsigned char c[4]; > }; > }; > > > > cell s; > > > Here c can be regarded as a integer > > s = 234; > > s.n[0] = 'ab'; said another way: > > s.c[0] = 'a'; > s.c[1] = 'b'; > > > Can something like this be expressed in BETA now or in the future? > If you want to be able to access an integer as an array of char, or do similar type-unsafe things the answer is no (present, and highly likely in the future). On the other hand, if you are using a union to save memory, it can easily be done using polymorphism. For example: Cell: (##); IntCell: Cell(# i: @integer #); CharCell: Cell(# c: [4]@Char #); .... Then you can choose the optimal representation of a Cell at runtime, not having to allocate memory for an integer if it contains an array of char and vice-versa. To access the cell you need to check its type first. /Rene