Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > Re: working aro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 7 Topic 139 of 211
Post > Topic >>

Re: working around anonymous enum

by Hanford Carr <"handycarr<nospam>"@[EMAIL PROTECTED] > Feb 17, 2005 at 10:14 PM

Marco van de Voort wrote:
> 
> How (and if so, for what types) is low() and high() defined in ISO
Pascal
> (old and extended) ?
> 
> Discussion piece was this workaround for testing members in a set that
was
> defined using an anonymous enumeration, that fails in Delphi because
> high and low are not defined for set. It did work in FPC, probably
because
> it is defined there.
> 
> { imagine that this type is given, e.g. in a different module}
> type myset = set of ( a1,a2,a3,a4,a5,a6);
> 
> { the rest is effectively the workaround }
> const
>      beginmyset=ord(low(myset));
>      endmyset=ord(high(myset));
> type
>      uglyenum = beginmyset..endmyset;
>      uglyset= set of uglyenum;
> 
> var b : myset;
>     i : integer;
> 
> begin
>   b:=[a1,a2,a3];
>   for i:=ord(low(myset)) to ord(high(myset)) do
>     if i in uglyset(b) then writeln(i);
> end.

Wouldn't the ord (a1) always be equal 0?
A possible work around might be

const
	HiMySet = 8 * sizeof (myset);

Of course HiMySet will overshoot by some bits but now with

type uglyenum = 0..HiMySet-1;
{and} uglyset = set of uglynum;

    b:=[a1,a2,a3];
    for i := 0 to HiMySet do
        if i in uglyset (b) 
             then writeln (i);


the correct orders for the elements a1, a2 and a3 are written out. I can
see a potential problem if the unused hi bits of a "myset" are not set
to zero by the compiler.

Cheers Hanford




 7 Posts in Topic:
working around anonymous enum
Marco van de Voort <ma  2005-02-17 07:43:06 
Re: working around anonymous enum
John Reagan <john.reag  2005-02-17 16:44:23 
Re: working around anonymous enum
Marco van de Voort <ma  2005-02-17 20:26:14 
Re: working around anonymous enum
John Reagan <john.reag  2005-02-17 22:59:16 
Re: working around anonymous enum
Marco van de Voort <ma  2005-02-18 09:19:28 
Re: working around anonymous enum
Hanford Carr <"ha  2005-02-17 22:14:26 
Re: working around anonymous enum
Marco van de Voort <ma  2005-02-18 09:15:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 0:52:40 CDT 2008.