Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zephyr.ens.tek.com!vice!bobb From: bobb@vice.ICO.TEK.COM (Bob Beauchaine) Newsgroups: comp.lang.pascal Subject: Re: Sets Message-ID: <7563@vice.ICO.TEK.COM> Date: 7 Jun 91 01:24:50 GMT References: <27126@adm.brl.mil> Reply-To: bobb@vice.ICO.TEK.COM (Bob Beauchaine) Organization: Tektronix, Inc., Beaverton, OR. Lines: 49 In article <27126@adm.brl.mil> (Delfin R. Pascual Jr.) writes: > > Hi to everyone out there! > > I have a question about set elements in Pascal. Is there a way to reference >individual elements of a set (like array elements are referenced by a >subscript) without using sets of enumerated types? Well, not exactly... Since you don't mention a compiler, I'll assume (quite impudently) Turbo Pascal. A Turbo set can hold up to 256 elements. This requires, at one bit per element, 32 bytes of storage per set variable (bet you didn't know sets were so memory hungry). There are two direct methods I can think of that will allow you to access the individual bytes of a set (though not the individual bits, at least w/o a little extra work). You can use either a variable typecast, or an absolute variable. Here's an example code fragment that does both: type set_array = array[1..32] of byte; var a_set : set of char; { Set base type. Could be any ordinal type } a_set_array : set_array absolute a_set; { Array on top of a_set } i : integer; . . . { Either method should work } for i := 1 to 32 do begin writeln(set_array(a_set)[i]); { Use a typecast } writeln(a_set_array[i]); { Use the predefined array } end; Note that both of these expressions for the set values could also appear on the left hand side of an assignment statment. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Bob Beauchaine bobb@vice.ICO.TEK.COM C: The language that combines the power of assembly language with the flexibility of assembly language. "It seems that the less a statesman amounts to, the more he appears to love the flag".