Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!elroy!orion.cf.uci.edu!uci-ics!ics.uci.edu!milne From: milne@ics.uci.edu (Alastair Milne) Newsgroups: comp.lang.pascal Subject: Re: Enumerated types in TP40 Message-ID: <7250@paris.ics.uci.edu> Date: 11 Feb 89 12:10:38 GMT References: <363@lafcol.UUCP> <950016@hpcllmr.HP.COM> Sender: news@paris.ics.uci.edu Reply-To: Alastair Milne Distribution: usa Organization: University of California, Irvine - Dept of ICS Lines: 28 In article <950016@hpcllmr.HP.COM> mark@hpcllmr.HP.COM (Mark Rozhin) writes: >>I believe something like sizeof(Enum1) div sizeof(Enum1(ord(One))) will do the >>trick, but I'm unable to test this right now... > >what does sizeof( ) mean? The same as "sizeof(anything-else)": the amount of memory, typically in bytes, required to store that value; or if the argument is a type, then the amount needed for a value of that type. I'm not quite following the proposed use of "sizeof" here. On the one hand, it looks as if it's being used to measure the ordinality (right term?) of an enumeration -- which it won't do. And the expression "sizeof(Enum1) div sizeof(Enum1(ord(One)))" looks as if it should yield one, since the arguments being passed to "sizeof" are equivalent. I have yet to encounter a way dynamically to determine the number of values in an enumeration, short of having a dialect which provides a MAX function. A fix that's not too hard to use is to have a constant "lastValue" declared as the final value in the enumeration. Besides providing an upper limit for scans, its ordinal is the number of values in the type, less 1. Of course, this takes advantage of TP4/5's relaxed ordering and counting of CONST, TYPE, and VAR sections. If anybody has a better way, I'd be interested to hear. Alastair Milne